Why don't we get compile errors on inline code errors in asp.net mvc views f.eks
<h1><%= ViewData.Model.Title.Tostrig() %></h1>
The code above will build just fine. Wrong spelling in webform controls will give you an error so I can't see why this isn't supported in asp.net mvc
EDIT: Luckily there seem to be a fix included in the first RC for asp.net mvc http://weblogs.asp.net/scottgu/archive/2008/12/19/asp-net-mvc-design-gallery-and-upcoming-view-improvements-with-the-asp-net-mvc-release-candidate.aspx
The HandleErrorAttribute is an attribute that can be used to handle exceptions thrown by an action method or a controller. You can use it to display a custom view on a specific exception occurred in an action method or in an entire controller.
You can handle default errors at the application level either by modifying your application's configuration or by adding an Application_Error handler in the Global. asax file of your application. You can handle default errors and HTTP errors by adding a customErrors section to the Web. config file.
The ASPX files in both ASP.NET and ASP.NET MVC are not compiled from the Visual Studio IDE. This is often the cause for "false positives" as you have pointed out.
I often add the aspnet_compiler as a post build action to find those errors. You will add some time to your build process, but in exchange for the wait you should be able to spot these errors more easily.
Following from Jason's answer, this line should work on most projects:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -v / -p "$(ProjectDir)\"
Or for .NET 4 projects:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler -v / -p "$(ProjectDir)\"
Source - Compiling aspx templates using aspnet_compiler
All you need to do is change the MvcBuildViews property to true in the project file.
e.g.
<PropertyGroup>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>
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