具有多个布局的renderSection(scrumble)

时间:2018-06-11 18:06:34

标签: c# asp.net-mvc

我怀疑renderSection是如何工作的。

我有一个包含2个布局的页面。

在第一个布局上,

@using Newtonsoft.Json
@using PortalInstitucional.WebSite.Models;

@{
    ViewBag.Title = "_Layout";
}

@model BaseModel

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">

    <link rel="shortcut icon" href="@Url.Content("/favicon.ico")" type="image/x-icon" />
    <title>My Home</title>

    <meta name="@Model.SEODescricao">
    <meta name="@Model.SEOTitulo">

    <!--Dynamic Metatags-->
    @RenderSection("MetaTags",false)

    @*<link rel="stylesheet" href="@Url.Content("~/Assets/js/lib/jquery-toastr/toastr.min.css")" />*@

    <!--Dynamic Style Code-->
    <style type="text/css">
        @RenderSection("StyleCode", false)
    </style>

       <!--Dynamic Style Files-->
    @RenderSection("StyleFiles", false)
</head>
<body>

    <input type="hidden" class="troca" value="" />

    @RenderSection("sectionheader", required: false)

    @RenderBody()
    @RenderSection("sectionfooter", required: false)

    <!-- js -->

    <script type="text/javascript" src="@Url.Content("~/Assets/portal/js/lib/jquery-1.12.3.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Assets/portal/js/lib/bootstrap-3.3.7.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Assets/portal/js/lib/jquery.lazy.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Assets/portal/js/lib/jquery.mobile.custom-1.4.5.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Assets/portal/js/lib/jquery.easing-1.3.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Assets/portal/js/lib/owl.carousel-2.4-custom.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Assets/jquery.cookie.min.js")"></script>

    <!-- diagrammer scripts-->
    <script type="text/javascript" src="@Url.Content("~/Assets/portal/js/main.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Assets/portal/js/carousel-index-produtos.js")"></script>

    <!--dynamic script files-->
    @RenderSection("ScriptFiles", false)

    <script>
        jQuery(document).ready(function () {

            @RenderSection("ScriptCodes", false)
        });
    </script>
</body>
</html>

在第二个布局上,

@using PortalInstitucional.WebSite.Models

@model BaseModel

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@RenderSection("MetaTags",false)
@RenderSection("StyleFiles", false)
@RenderSection("ScriptFiles", false)



@section StyleFiles {
    <!-- responsive franmework -->
    <link rel="stylesheet" href="@Url.Content("~/Assets/portal/css/lib/bootstrap-3.3.7.min.css")" />
    <link rel="stylesheet" href="@Url.Content("~/Assets/portal/css/custom-grid.css")" />

    <!-- diagrammer styles -->
    <link rel="stylesheet" href="@Url.Content("~/Assets/portal/css/reset.css")"/>
    <link rel="stylesheet" href="@Url.Content("~/Assets/portal/css/main.css")" />
    <link rel="stylesheet" href="@Url.Content("~/Assets/portal/fonts/fonts.css")" />
}

@section sectionheader {
    <div class="fader"></div>
    @Html.Partial("Portal/_Header", Model.Header)
}
@RenderBody()

@section sectionfooter {
    @Html.Partial("Portal/_Footer", Model.Footer)
}

@section ScriptFiles
{
    <script type="text/javascript" src="@Url.Content("~/Assets/plugins/jquery-mask/jquery.mask.min.js")"></script>
}

@section ScriptCodes {
    @RenderSection("ScriptCodes", false);
}

最后一页

@model PostModel

@{
    ViewBag.Title = Model.SEOTitulo;
    Layout = Model.Layout;
}


@section MetaTags{
    <meta property="og:url" content="@Request.Url" />
    <meta property="og:type" content="website" />
    <meta property="og:title" content="@Model.SEOTitulo" />
    <meta property="og:description" content="@Model.SEODescricao" />
    <meta property="og:image" content="@( Model.Post.ImageHighlight != null ? Model.Post.ImageHighlight.CaminhoVirtual : string.Format("{0}Assets/img/noticia-item-vazia.jpg", AppSettings.UrlSite) )" />
    <meta property="og:image:type" content="@( Model.Post.ImageHighlight != null ? Model.Post.ImageHighlight.TipoMIME : "image/jpeg" )" />
    <meta property="fb:app_id" content="@Model.IdFacebookApp" />
}

@section StyleFiles{
    <!-- image gallery -->
    <link href="@Url.Content( Model.Assets + "css/lib/owl.carousel-2.4-custom.min.css")" rel="stylesheet">
    <link rel="stylesheet" href="@Url.Content( Model.Assets + "css/lib/photoswipe-4.0.5.min.css" )" />
    <link rel="stylesheet" href="@Url.Content( Model.Assets + "css/lib/photoswipe-default-skin-4.0.5.min.css" )" />
    <!-- video gallery -->
    <link rel="stylesheet" href="@Url.Content( Model.Assets + "css/lib/jquery.fancybox-2.1.5.css" )" />
    <!-- galeria de áudios -->
    <link rel="stylesheet" href="@Url.Content( Model.Assets + "css/lib/audio-player.css" )" />

    <!-- Root element of PhotoSwipe. Must have class pswp. -->
    @Html.Partial("_PhotoSwipe")
}

@Html.Partial("Banners/_BannerHeaderFixo", Model.Assets)

<section class="conteudo conteudo-blog">
    <div class="container">
        <div class="row">
            <div class="col-md-9">
                <div class="btn-box-voltar">
                    <a href="@Request.UrlReferrer" target="_self">Voltar</a>
                </div>
                <div class="header">
                    <div class="row">
                        <div class="col-lg-12">
                            <p class="data">@Model.Post.DataPublicacao.ToLongDateString()</p>
                            <h1>@Model.Post.Titulo</h1>
                            <h2>@Model.Post.Categoria.Nome</h2>
                            @Html.Partial("_Tags", Model.Post.Tags)
                        </div>
                    </div>
                </div>
                <div id="textoConteudo">
                    @Html.Raw(Model.Post.Html)

                </div>
            </div>
            <div class="col-md-3">

                @Html.Partial("_Busca", new BlogModel(Model.SiteBase))

                @Html.Partial("_Categorias", Model.Categorias)

                @Html.Partial("_OutrosPosts", Model.Posts)
            </div>
        </div>
    </div>
</section>

@section ScriptFiles{
    <script type="text/javascript" src="@Url.Content( Model.Assets + "js/lib/jquery.easing-1.3.min.js")"></script>
    <script type="text/javascript" src="@Url.Content( Model.Assets + "js/lib/jquery.mobile.custom-1.4.5.min.js")"></script>

    <!-- image gallery -->
    <script type="text/javascript" src="@Url.Content( Model.Assets + "js/lib/photoswipe-4.0.5.min.js" )"></script>
    <script type="text/javascript" src="@Url.Content( Model.Assets + "js/lib/photoswipe-ui-default-4.0.5.min.js" )"></script>

    <script type="text/javascript" src="@Url.Content( Model.Assets + "js/lib/owl.carousel-2.4-custom.min.js")"></script>
    <script type="text/javascript" src="@Url.Content( Model.Assets + "js/image.gallery.js" )"></script>
    <!-- video gallery -->
    <script type="text/javascript" src="@Url.Content( Model.Assets + "js/lib/jquery.fancybox-2.1.5.js" )"></script>
    <script type="text/javascript" src="@Url.Content( Model.Assets + "js/lib/jquery.fancybox.media-1.0.6.js" )"></script>
    <script type="text/javascript" src="@Url.Content( Model.Assets + "js/video.gallery.js" )"></script>
    <!-- audio gallery --->
    <script type="text/javascript" src="@Url.Content( Model.Assets + "js/lib/audioplayer.js" )"></script>
    <script type="text/javascript" src="@Url.Content( Model.Assets + "js/default.scripts.detail.js" )"></script>


}

@section ScriptCodes{
    Detail.start();

    //update image for share
    var link = "@Request.Url";
    var description = "@Model.SEODescricao";
    var title = "@Model.SEOTitulo";
    var media = "@( Model.Post.ImageHighlight != null ? Model.Post.ImageHighlight.CaminhoVirtual : string.Empty )";

    addthis.update('share', 'description', description);
    addthis.update('share', 'url', link);
    addthis.update('share', 'title', title);
    addthis.update('share', 'media', media);

    // Once that's all done, call addthis.toolbox()
    addthis.toolbox('.addthis_inline_share_toolbox_vcqt');

    //load asynchronous
    addthis.init();
}

renderSection被加载到位置之外。例如,@ renderSection MetaTags出现在正文,而不是标题,就像在布局中指定的那样 因此,控制台显示与jQuery和其他js函数相关的错误。

如果我没有设置false,则在renderSection中,页面不会加载。

但是,我的问题是为什么renderSections不会写在正确的位置。

0 个答案:

没有答案