ASP .NET MVC How to pass data between views
I have this scenarion. There are Boards. And Threads. Therads can be created only on boards, and for that they need to be provided with board ID, Name or something like that, to let SQL know where it should add thread.
By now I've been using hidden fields to pass data between views, but more I used them tehre was more trash in code like ViewBags, unnesseary attributes in methods etc.
Are there cleaner ways 开发者_开发百科to do it ?
Pass the model back to the view.
so if you have a model called Data with a field called Name then;
Data fvm = new Data{ Name = "my name"};
return View(fvm)
then inherit the view from the model and use;
<%= Model.Name %>
to get data.
Then as you move from view to view you pass the form back to the view with either ajax, jQuery submit plugin or a submit button which should also be the model.
then in your controller;
public actionresult myciew(Data model)
{
//do something with the model
}
精彩评论