【问题标题】:Visual Studio compilation omit's the code inside the.aspx files?Visual Studio 编译省略了.aspx 文件中的代码?
【发布时间】:2012-01-09 12:51:53
【问题描述】:

我在 Visual Studio 2010 Prosessional(在 ASP.NET MVC 3 项目中)中发现了一件奇怪的事情。如果我有下面这样的语法,编译器不会检查里面是否有任何错误。

<% 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>

<% } %>

只有当我在解决方案中自己打开那个 .aspx 页面时,编译器才会验证代码。

那么,如何强制编译器自动检查语法 在编译项目时?

【问题讨论】:

    标签: visual-studio-2010 asp.net-mvc-3


    【解决方案1】:

    编译视图时可以。这里是a post about that.

    Here is the tutorial on how to do it,被接受为答案

    来自社区 wiki 帖子:

    在你构建了你的解决方案来编译它之后,你会看到你的 视图也会被编译。

    注意来测试它,故意破坏你的一个视图上的一些代码,然后 尝试构建。你会看到你会收到一条错误消息

    这样做意味着:打破观点;打破构建。这似乎是你想要的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-20
      • 1970-01-01
      相关资源
      最近更新 更多