In ASP.Net MVC models and controllers are pre-compiled whereas views are compiled at run-time, so any error in view cannot be detected until and unless it is run on the browser. By default ASP.Net MVC does not allow you to detect errors at compile time but you can change it by changing the MvcBuildViews property.
After that reload the project and build it on Release mode, you will not get error in Debug Mode. After building if you have any error in your Razor View you will get an error like below, in our case we have misspelled ViewBag to ViweBag.
One more option is to use RazorGenerator. RazorGenerator is a custom tool for Visual Studio that allows processing Razor files at design time instead of run time. So when .cshtml will be compiled using RazorGenerator it will create .generated.cs file thus will give you an error when you will compile it.
Please Like and Share CodingDefined.com blog, if you find it interesting and helpful.