One of the strengths of MVC is the automatic assembly function, that is, the HTNL name or ID of the foreground page is the same as the background code viewdata["ID", and assigns a value to the viewdata["id", then the viewdata["id" will be automatically rendered when the page renders. The data is displayed on the foreground page. Here's an example:
The following code is available on the foreground page:
<%: Html.dropdownlist ("City")%>
The code in the action is as follows:
viewdata["City" = new list<selectlistitem> ()
{
New selectlistitem{selected=false,text= "Beijing", value= "1"},
New selectlistitem{selected=false,text= "Shanghai", value= "2"},
New selectlistitem{selected=false,text= "Guangzhou", value= "3"},
};
return View ();
}
It will automatically assemble the data into the foreground page.
This automatic assembly function is still possible when using strongly typed data.
<td> Customer Code: </td><td><%: Model.id%></td>
<td> Customer Code: </td><td><%: Html.textbox ("Id")%></td>
<td> Customer Code: </td><td><%: Html.textboxfor<userinfo,int> (c=>c.id)%></td>
These three ways can realize automatic data assembly function.
Automated assembly capabilities in MVC