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 @Model will contain all the data of the current page. So when you access a page on your site you can get data from that page with using the @Model.
The declaration at the top will do two things for you: It will allow intellisence to know what type you are using when you type in @Model or use any of the Html helper extensions. It will also check at runtime that model passed in can be cast to the type the view expects.
A Razor Page is almost the same as ASP.NET MVC's view component. It has basically the syntax and functionality same as MVC. The basic difference between Razor pages and MVC is that the model and controller code is also added within the Razor Page itself. You do not need to add code separately.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With