gpt4 book ai didi

asp.net-mvc - MVC Razor @section 不理解脚本

转载 作者:行者123 更新时间:2023-12-03 01:05:52 27 4
gpt4 key购买 nike

我有:

  • VS 2013
  • MVC 5.2.2
  • Razor 3.2.2

如果您还有其他需要了解的信息,请告诉我。

此问题仅发生在一个 View 页面上。

我有一个 View ,所有 HTML 标签都正确关闭

这是您的标准 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 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...

没有其他页面有此问题。

关于如何解决这个问题有什么想法吗?

最佳答案

异常消息显示:

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 表示 View 可以选择提供此部分。

现在,当您的 View 渲染时, View 中的 @section Scripts { ... } 的内容将被渲染到 @RenderSection("Scripts", false ) 在布局页面中调用。

关于asp.net-mvc - MVC Razor @section 不理解脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26168593/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com