I have been studying asp.net for about one months, has always been half-baked, because a long time before doing Java development, there is no time to quiet down the heart to learn, coupled with the ASP.net framework is also very complex, time is also to see the spinning, so can only see a little record, slowly accumulate, Come to the conclusion.
Action to view the transfer of data is very simple, there are many ways, the most direct is that we pass Model to view, which in itself is the meaning of MVC. If you are displaying some messages, such as an error message, you can use ViewData:
Public ActionResult Index ()
{
viewdata["message"] = "Hello word!";
return View ();
}
Then the view:
<asp:content id= "indexcontent"
contentplaceholderid= "maincontent" runat= "Server" >
<%: viewdata[" Message "]%>
</asp:Content>
Actual effects such as:
As we can see, ViewData is a dictionary that holds the key-value pairs.
Since the action can pass data to the view, can view modify the data and then pass it back to the action?
We modify the code like this:
Public ActionResult Index ()
{
viewdata["message"] = "Hello word!";
return View ();
}
Public ActionResult About ()
{
String message = viewdata[' message '] as string;
if (message = = "Hello")
{
viewdata["message2"] = "modified";
}
else
{
viewdata["message2"] = "no modification";
}
return View ();
}