已经定义了以下部分,但尚未为布局页面“〜/Views/Shared/_Layout.cshtml"呈现 [英] The following sections have been defined but have not been rendered for the layout page “~/Views/Shared/_Layout.cshtml”

查看:265
本文介绍了已经定义了以下部分,但尚未为布局页面“〜/Views/Shared/_Layout.cshtml"呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个ActionResult:

I've this ActionResult:

[EncryptedActionParameter]
[CheckExternalUserRegisterSigned]
public ActionResult ExpedienteIIT(int idExpediente)
{
    ExpedienteContainerVM model = this.GetExpedienteVMByIdExpediente(idExpediente);
    return View("ExpedienteIIT", model);
}

ExpedientIIT视图: https://jsfiddle.net/pq16Lr4q/

ExpedientIIT View: https://jsfiddle.net/pq16Lr4q/

_Layout.cshtml: https://jsfiddle.net/1ksvav43/

_Layout.cshtml: https://jsfiddle.net/1ksvav43/

所以当我返回视图时,我得到了这个错误:

So when I return the view I got this error:

我试图放入console.logs来查看视图是否已渲染但未渲染...

I tried to put console.logs to see if the view is rendered but is not rendered...

好,错误在这里:

@model PortalSOCI.WEB.ViewModels.IIT.ExpedienteContainerVM


    @{
        ViewBag.Title = String.Format(PortalSOCI.WEB.Resources.ExpedienteIIT.TituloExpedienteIIT, Model.Expediente.NumeroExpediente);
    }

    @section JavaScript  /// <-------------------- ERROR
    {
        @Html.Raw(ViewBag.message)
    @

能帮我吗?

推荐答案

阅读完您的代码后,我觉得

edit: After reading your code, i feel like

@RenderSection("scripts", required: false)

应该是

@RenderSection("JavaScript", required: false)

我认为还会给您带来麻烦的另一件事是,您在主体中定义了"JavaScript"部分.这意味着,如果您有任何视图,则忘记添加该视图

an other thing that I think will give you trouble is the fact that you define your "JavaScript" section in the body. This means that if any of your views you forget to add that

@section JavaScript
{
    @Html.Raw(ViewBag.message)
}

您将收到一个Section JavaScript not defined错误.就您而言,感觉该节的定义应该在_layout.cshtml中.

you'll get a Section JavaScript not defined error. In your case, feels like the section's definition should be in the _layout.cshtml.

此错误很可能意味着您已定义了JavaScript部分,但未在任何地方渲染它. 您需要在layout.cshtml

This error most likely means that you have defined the JavaScript section but have not rendered it anywhere. You need to call @RenderSection("JavaScript") somewhere in your layout.cshtml

@section JavaScript
{
}

将允许您创建一个名为"JavaScript"的部分,但是要将该部分的内容实际打印"到输出HTML文件(将发送给客户端),则需要调用@RenderSection("JavaScript").该部分的内容将打印在调用RenderSection的位置.

will let you create a section called "JavaScript", but to actually "print" the content of this section to the output HTML file (that will be sent to the client) you need to call @RenderSection("JavaScript"). The content of the section will be printed where the call to RenderSection is located.

这篇关于已经定义了以下部分,但尚未为布局页面“〜/Views/Shared/_Layout.cshtml"呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆