views:

68

answers:

1

I'm starting to use Asp.net MVC. It is recommended to use the <% and %> tags to embed the source code in the HTML, since it's easier to read.

Unfortunately though Visual Studio can't detect any errors in the code at compile time. This is a very bad thing.

For example:

<body>
    <form action="LogOn.aspx">
        <div>
            <div><label for="txtLogOn_UserName"><%= LogOnView.UserName %> :</label></div>
            <div><%= Html.TextBox("txtLogOn_UserName")%></div>            
        </div>
    </form>
</body>

How can I be sure that LogOnView.UserName is a valid statement? As an analogy that code is similar to JS code; you can't know if there will be errors until you run it.

A possible solution could be to create a test project, but I don't like that idea and I don't think I should be forced to create a test project to solve this problem.

Note: This problem will not occur if I use the code-behind coding style.

+4  A: 

You could use the aspnet_compiler as a post-build action:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -v / -p "$(ProjectDir)\"

More info here.

Edit for .NET 4.0 users:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler -v / -p "$(ProjectDir)\"
Dan Atkinson
It's work. Thank a lot.
Soul_Master
You're welcome!
Dan Atkinson