By default, razor views are not compiled with projects. They compile at runtime.
Problem:
Razor view will not give you a compile time error if you have used a wrong property name or property name changes. It throws a runtime exception.
Solution:
You can turn on compilation in your project file.
Open the .csproj file in notepad. Find <mvcbuildviews> in the .csproj file. Change <MvcBuildViews>false</MvcBuildViews> to <MvcBuildViews>true</MvcBuildViews>.
Now, all the razor views will be precompiled with other parts of the MVC project.
Related Articles
- Difference between Html.Partial() and Html.RenderPartial() in ASP.NET MVC
- Difference between Html.RenderBody() and Html.RenderSection() in ASP.NET MVC
- How to enable bundling and minification in ASP.NET MVC?
- How to enable client side validation in ASP.NET MVC?
- How to display an error message using ValidationSummary in ASP.NET MVC?
- How to bind a model to a partial view in ASP.NET MVC?
- View in ASP.NET MVC