什么是强类型的ASP.NET MVC视图 [英] What is strongly-typed View in ASP.NET MVC
问题描述
什么是强类型的ASP.NET MVC视图?
What is strongly-typed View in ASP.NET MVC?
推荐答案
这是从<一个派生的aspx页面href=\"http://msdn.microsoft.com/en-us/library/dd470798.aspx\"><$c$c>System.Web.Mvc.ViewPage<TModel>$c$c>.据说,这种看法是强类型的类型的TModel
。其结果是该有此视图内的型号财产这类型的的TModel
,并允许您直接访问模型的性质是这样的:
It is an aspx page that derives from System.Web.Mvc.ViewPage<TModel>
. It is said that this view is strongly typed to the type TModel
. As a consequence to this there's a Model property inside this view which is of type TModel
and allows you to directly access properties of the model like this:
<%= Model.Name %>
<%= Model.Age %>
在这里仿佛从<派生你的aspx页面href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.viewpage.aspx\"><$c$c>System.Web.Mvc.ViewPage$c$c>你需要从拉动值的ViewData code>视图不再知道有关
的TModel
键入
<%= (string)ViewData["Name"] %>
<%= (int)ViewData["Age"] %>
甚至更糟糕的:
<%= ((SomeModelType)ViewData["model"]).Name %>
和有此类code无编译时的安全性。
and there's no compile time safety in such code.
另请注意,还有的<一个href=\"http://msdn.microsoft.com/en-us/library/dd505223.aspx\"><$c$c>ViewUserControl<TModel>$c$c>对口强类型的谐音(ASCX)。
Notice also that there's the ViewUserControl<TModel>
counterpart for strongly typed partials (ASCX).
这篇关于什么是强类型的ASP.NET MVC视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!