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

user576510 picture user576510 · May 25, 2014 · Viewed 17.7k times · Source

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.

Answer

Wiktor Zychla picture Wiktor Zychla · May 25, 2014

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