Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

razor views are not giving compile time error [duplicate]

I've recently installed VS 2012 Professional.

When i try to build my MVC4 Web Project. It doesn't recognize error in razor view when i do "Build" or "Re-Build".

Example :
I removed a namespace from the project / or say renamed it. i build the solution, it gave me errors in all cs files, which i fixed by changing the namespace. The entire solution build successfully. When i run the project it gave me Compilation Error saying that namespace not found, because the old namespace was still referred in some of the views (*.cshtml files).

Expected Solution :
I wish when i do "Build" or "Re-Build", it should recognize such errors and show me along with any other errors.

This was working fine with VS 2010, am i missing any configuration?

Thanks In Advance !! Amit

Edit I found the answer myself, i think it was early to post the question :

razor syntax with errors compiles when it should not compile

Another Problem

After changing value to True in .csproject file, when i start building the project it shows error, but it shows only one error at a time. let's say, i've 5 errors in total 3 views. it would just show me one error. Is there any solution so that it shows all the 5 errors ?

like image 684
Amit Andharia Avatar asked Apr 17 '13 06:04

Amit Andharia


People also ask

How do I enable Razor runtime compilation?

Enable runtime compilation at project creationSelect either the Web Application or the Web Application (Model-View-Controller) project template. Select the Enable Razor runtime compilation checkbox.

Do Cshtml files get compiled?

. cshtml files will be compiled just-in-time, that is when a request arrives regarding those pages. However controllers are pre-compiled and stored into your project's DLL files.

Is Razor a Mvvm?

Razor Pages is sometimes described as implementing the MVVM (Model, View ViewModel) pattern. It doesn't. The MVVM pattern is applied to applications where the presentation and model share the same layer. It is popular in WPF, mobile application development, and some JavaScript libraries.

What is @model in Razor?

The @ symbol is used in Razor initiate code, and tell the compiler where to start interpreting code, instead of just return the contents of the file as text. Using a single character for this separation, results in cleaner, compact code which is easier to read.


1 Answers

When i try to build my MVC4 Web Project. It doesn't recognize error in razor view when i do "Build" or "Re-Build".

Seems normal. Razor views are dynamically compiled by the ASP.NET runtime. If you want your views to be built at compile-time you could add the following option to your .csproj file:

<PropertyGroup>     <MvcBuildViews>true</MvcBuildViews> </PropertyGroup> 

You may take a look at the this article for more details.

like image 98
Darin Dimitrov Avatar answered Oct 21 '22 23:10

Darin Dimitrov