1 Processing of strong types
first, you must have an entity class for an object, UserInfo is an entity class, as Follows:
public class UserInfo ()
{
public int id{set;get;}
public string username{set;get;}
public int userage{setl;get;}
}
The action for invoking this entity class is as Follows:
Public ActionResult qiangleixing ()
{
UserInfo userinfo=new UserInfo ();
UserInfo. id=1;
UserInfo. Username= "GRL";
UserInfo. userage=20;
viewdata.model=userinfo;
return View ("View1");
}
The code for displaying information on page View1 is as Follows:
The use of strongly typed code requires the introduction of a strongly typed model, which is the top piece of code on the Page. In the use of the time only need to use the model of the way you can recall the information needed to Use.
Why use model at the front desk is possible for the following reasons:
When you open the Model's definition function with the anti-compilation software, the current code is as Follows:
Public TModel Model ()
{
get{
Return This. viewdata.model;
}
}
That is, the. NET platform helps us encapsulate a layer, if we do not encapsulate this layer of function, we need to write the code when using the foreground is
<%: ViewData.Model.Id%>
The following are the specific illustrations:
So we can use strongly typed data so conveniently.
2 Weak type
The action method that handles the background code is as Follows:
Public ActionResult Index ()
{
DataTable dt=sqlhelper.excutedatatable ("select ID, Class, Department, Teacher from tb_class");
viewdata["dt"]=dt;
return View ("Home");
}
The code in the home page is as Follows:
The difference between a strong type and a weak type of MVC