MVC4 Razor difference in @model and @inherit in view header?

蹲街弑〆低调 提交于 2019-11-30 11:05:54

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>

and

@model ModelClass

Reference: http://weblogs.asp.net/scottgu/archive/2010/10/19/asp-net-mvc-3-new-model-directive-support-in-razor.aspx

They are the same (i.e. indicate strongly-typed model classes) but @inherit is more verbose (because of the full path). @inherit was the only way to do it when razor was first introduced (pre-release of MVC 3 I think), but I haven't seen it used for years.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!