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:
Please see this example.
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
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.
来源:https://stackoverflow.com/questions/23854556/mvc4-razor-difference-in-model-and-inherit-in-view-header