MVC Razor @section无法理解脚本

编程入门 行业动态 更新时间:2024-10-24 18:26:27
本文介绍了MVC Razor @section无法理解脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有:

  • 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 Scripts

Resharper报告:无法解析部分脚本"

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无法理解脚本

本文发布于:2023-11-15 10:34:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1593656.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   MVC   Razor   section

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!