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

前端 未结 2 626
孤独总比滥情好
孤独总比滥情好 2021-01-01 15:09

To make a view strongly typed we can use @model and @inherit. Can you please tell me what the difference is between both of them?

Edit:

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-01 15:51

    The difference is as follows: if your view inherits from WebViewPage then your model directive points to T.

    In other words, these two are equivalent

    @inherits System.Web.Mvc.WebViewPage
    

    and

    @model ModelClass
    

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

提交回复
热议问题