在@model和@inherit鉴于头MVC4剃刀区别? [英] MVC4 Razor difference in @model and @inherit in view header?
问题描述
要做出一个视图强类型,我们可以使用 @model
和 @inherit
。能否请你指导我什么是他们两个人的差异。我新来的MVC,无法弄明白。
To make a view strongly typed we can use @model
and @inherit
. Can you please guide me what is difference in both of them. I m new to MVC and couldn't figure it out.
请指导。
编辑:
请参见下面的例子: <一href="http://www.arrangeactassert.com/asp-net-mvc-razor-view-best-practices-keep-logic-out-of-your-razor-views/" rel="nofollow">http://www.arrangeactassert.com/asp-net-mvc-razor-view-best-practices-keep-logic-out-of-your-razor-views/
推荐答案
所不同的是:如果你的视图继承了 WebViewPage&LT; T&GT;
然后你的模型指导点以 T
。
The difference is as follows: if your view inherits from WebViewPage<T>
then your model directive points to T
.
在换言之,这两个是相同的
In other words, these two are equivalent
@inherits System.Web.Mvc.WebViewPage<ModelClass>
和
@model ModelClass
参考:<一href="http://weblogs.asp.net/scottgu/archive/2010/10/19/asp-net-mvc-3-new-model-directive-support-in-razor.aspx">http://weblogs.asp.net/scottgu/archive/2010/10/19/asp-net-mvc-3-new-model-directive-support-in-razor.aspx
这篇关于在@model和@inherit鉴于头MVC4剃刀区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!