我有:
如果您还需要了解其他信息,请告诉我。
此问题仅发生在一个视图页面上。
我有一个视图,所有HTML标记都已正确关闭
这是你的标准观点......
@model MyNameSpace.Models.Inquiry
@{
var hasFormSetup = Model != null && Model.FormSetup != null && Model.FormSetup.Count > 0;
if (hasFormSetup)
{
ViewBag.Title = Model.FormSetup[0].InquiryValue;
}
Layout = "~/Views/Shared/_LayoutInquiry.cshtml";
}
<style scoped>
ul {
list-style-type: none;
}
</style>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="container" style="margin-top: 5px;">
etc...
</div>
<div class="container" >
etc...
</div>
}
@section Scripts
{
<script type="text/javascript">
$(document).ready(function () {
etc...
});
</script>
}
但是...
就行了
@section Scripts
Resharper报告:“无法解析部分脚本”
当我跑步时,我得到例外:
Source: System.Web.WebPages
Target: Void VerifyRenderedBodyOrSections()
Type: HttpException
Message: The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_LayoutInquiry.cshtml": "Scripts".
Stack: at System.Web.WebPages.WebPageBase.VerifyRenderedBodyOrSections()
at System.Web.WebPages.WebPageBase.PopContext()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.WebPages.WebPageBase.<>c__DisplayClass3.<RenderPageCore>b__2(TextWriter writer)
at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)
at System.Web.WebPages.WebPageBase.Write(HelperResult result)
at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)
at System.Web.WebPages.WebPageBase.PopContext()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
etc...
没有其他页面存在此问题。
关于如何解决此问题的任何想法?
答案 0 :(得分:17)
异常消息说:
以下部分已定义,但尚未针对布局页面“〜/ Views / Shared / _LayoutInquiry.cshtml”:“Scripts”进行渲染。
这表明您的_LayoutInquiry.cshtml
页面未为Scripts
部分设置占位符。您可以将@RenderSection("Scripts", false)
添加到适当位置的布局页面,false
表示视图可以选择提供此部分。
现在,当您的视图呈现时,视图中@section Scripts { ... }
的内容将呈现在布局页面中@RenderSection("Scripts", false)
调用的位置。
答案 1 :(得分:1)
对于其他可能会在这里结束的人。一切正常,但是ReSharper抱怨缺少Section和Styles。
我们的情况是共享文件夹中有_Layout.cshtml和_Layout.Mobile.cshtml。
答案 2 :(得分:0)