我有:
- VS 2013
- MVC 5.2.2
- 剃刀3.2.2
让我知道您是否还需要了解其他内容.
Let me know if there's anything else you need to know.
此问题仅在一个视图页面上发生.
This problem only happens on one view page.
我有一个视图,其中所有HTML标记均已正确关闭
I have a View with all HTML tags closed off properly
这是您的标准视图...
It's your standard view...
@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 ScriptsResharper报告:无法解析部分脚本"
Resharper reports: "Cannot resolve section Scripts"
我跑步时遇到异常:
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...没有其他页面出现此问题.
No other page has this issue.
关于如何解决此问题的任何想法?
Any ideas as to how I can fix this?
推荐答案该异常消息显示:
已经定义了以下部分,但尚未为布局页面〜/Views/Shared/_LayoutInquiry.cshtml"呈现:脚本".
The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_LayoutInquiry.cshtml": "Scripts".
这表明您的_LayoutInquiry.cshtml页未为Scripts部分设置占位符.您可以通过在布局页面的适当位置添加@RenderSection("Scripts", false)来实现此目的,其中false表示视图可以有选择地提供此部分.
This suggests that your _LayoutInquiry.cshtml page does not setup a placeholder for a Scripts section. You can do this by adding @RenderSection("Scripts", false) to your layout page in the appropriate location, where the false indicates that views may optionally supply this section.
现在,在渲染视图时,视图中@section Scripts { ... }的内容将被渲染到布局页面中@RenderSection("Scripts", false)调用的位置.
Now, when your view renders, the contents of @section Scripts { ... } in your view will be rendered into the location of the @RenderSection("Scripts", false) call in your layout page.
更多推荐
MVC Razor @section无法理解脚本
发布评论