【问题标题】:MVC-Project seems to be build partially - EditorTemplates breakpoints not hitMVC-Project 似乎部分构建 - EditorTemplates 断点未命中
【发布时间】:2016-05-27 09:37:28
【问题描述】:

我的 MVC5 项目遇到了非常奇怪的问题。添加时

@RenderBody()
@{
    throw new Exception();
}

我的~/Views/Shared/Master.cshtml 在运行时抛出异常。 但是,在我的~/Views/Shared/EditorTemplates/DateTime.cshtml 中不会运行相同的代码。

看起来,EditorTemplates-文件夹(其内容)没有被构建,因为断点也不会被命中,说

当前不会命中断点。没有为此文档加载任何符号。

我已经删除了 bin/obj 文件夹,清理了 ASP.NET Temp 文件夹,清理并重建了我的项目,检查了项目设置,重新启动了本地 IIS... 目前我的选择已经不多了。我什至将整个项目重新克隆到一个新的本地文件夹。还是一样。

怎么会发生一个断点被命中而另一个没有被命中的情况?即使他们在同一个程序集中?

编辑#1

模板配合使用

@Html.EditorFor(m => m.Start, "~/Views/Shared/EditorTemplates/_DateTimePicker.cshtml")

在另一个视图中。那里设置的断点会被命中。那里也有变化。

它至少会呈现我的_DateTimePicker.cshtml 的一些旧版本,但不会呈现当前版本。在本地哪里可以找到IIS使用的文件?

【问题讨论】:

    标签: c# visual-studio debugging dll build


    【解决方案1】:

    问题在于我如何称呼“模板”。

    @Html.EditorFor(m => m.Start, "~/Views/Shared/_DateTimePicker.cshtml")
    

    应该是

    @Html.EditorFor(m => m.Start, "_DateTimePicker")
    

    不知道为什么第一个版本没有抛出异常或给了我一些提示。

    【讨论】:

      【解决方案2】:

      抛出异常是因为您的应用程序在您的 Master.cshtml 文件上运行该点。如果您希望在 DateTime.cshtml 视图上引发异常或中断点,请将其添加为 Master.cshtml 文件的局部视图。

      Do this on your Master.cshtml:
      
      @Html.Partial("EditorTemplates/DateTime")
      

      【讨论】:

      • 我在Setup.cshtml 视图中使用@Html.EditorFor(m => m.Start, "~/Views/Shared/EditorTemplates/_DateTimePicker.cshtml") 调用模板。 Setup.cshtml 中的断点被击中,_DateTimePicker.cshtml 中没有。但是,至少它呈现了一些东西。旧的东西。在哪里可以找到本地部署的文件?
      猜你喜欢
      • 1970-01-01
      • 2019-01-08
      • 2021-04-25
      • 1970-01-01
      • 2018-10-17
      • 2018-08-09
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多