0

I've noticed a strange thing in the Visual Studio 2010 Prosessional (in the ASP.NET MVC 3 project). If I have the syntax like below, the compiler doesn't checks if there is any error inside.

<% foreach (var item in Model) { %>

<div class="author-box">
    <div class="author-box-header">
        <%: Html.ActionLink(item.Name, "", new { id = item.AuthorID }) %>
    </div>
    <div class="author-box-body">
        Books: <%: Html.DisplayFor(o => item.Books.Count) %> 
        // Here's the error, shoutld be item.Book.Count
    </div>
</div>

<% } %>

Only when I open that .aspx page by myself in the solution, then the compiler validates the code.

So, how to force the compiler to automatically chcecks the syntax while compilating the project ?

Tony
  • 12,405
  • 36
  • 126
  • 226

1 Answers1

3

You can when you compile your views. Here is a post about that.

Here is the tutorial on how to do it, which was accepted as answer

From the community wiki post:

after your build your solution to compile it, your will see that your view will be compiled too.

NOTE to test it, break some code on one of your view on purpose and try to build. you will see that you'll get an error message

So doing that means: break a view; break the build. Which seems like what you want

Community
  • 1
  • 1
Ron Sijm
  • 8,490
  • 2
  • 31
  • 48