已定义以下部分,但尚未针对布局页面“〜/ Views / Shared / _blanklayout.cshtml”:“JavaScript”进行渲染。

时间:2013-01-07 21:24:12

标签: asp.net-mvc

我收到错误: 当我尝试运行我的索引页面时抛出错误我应该在索引视图页面中添加什么? 以下部分已定义,但尚未针对布局页面“〜/ Views / Shared / _blanklayout.cshtml”:“JavaScript”进行渲染。

这是我的_blacklayout页面

@{
    Layout = null;
}
 <link type="text/css" rel="stylesheet" href="@Url.Content("~/content/reset.css")">
    <link type="text/css" rel="stylesheet" href="@Url.Content("~/content/layout.css")">
    <link type="text/css" rel="stylesheet" href="@Url.Content("~/content/core.css")">
@RenderBody()
<script type="text/javascript">
    adroll_adv_id = "6MFN5K54DVCUROYTS4BE5J";
    adroll_pix_id = "GR7KUS3M3FA7BE2HPTH5EX";
    (function () {
        var oldonload = window.onload;
        window.onload = function () {
            __adroll_loaded = true;
            var scr = document.createElement("script");
            var host = (("https:" == document.location.protocol) ? "https://s.adroll.com" : "http://a.adroll.com");
            scr.setAttribute('async', 'true');
            scr.type = "text/javascript";
            scr.src = host + "/j/roundtrip.js";
            ((document.getElementsByTagName('head') || [null])[0] ||
    document.getElementsByTagName('script')[0].parentNode).appendChild(scr);
            if (oldonload) { oldonload() }
        };
    } ());
    </script>
    <script type="text/javascript">

        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-19362393-2']);
        _gaq.push(['_setDomainName', 'netdocuments.com']);
        _gaq.push(['_trackPageview']);

        (function () {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();

</script>


**and this is my Index view page where I am using it:**

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_blanklayout.cshtml";
}

@section JavaScript{

 <script type="text/javascript">
     $(function () {
         $("a.fancybox").fancybox({
             'overlayShow': true,
             'autoSize': false,
             'autoResize': false,
             'autoDimensions': false,
             'enableEscapeButton': true,
             'showCloseButton': true,
             'width': 620,
             'height': 390,
             'type': 'iframe',
             'scrolling': 'no'
         });
     });
    </script>

     <link rel="stylesheet" href="@Url.Content("~/Content/fancybox/jquery.fancybox.css?v=2.1.2")" type="text/css" />
     <script type="text/javascript" src="@Url.Content("~/Content/fancybox/jquery.fancybox.pack.js?v=2.1.2")"></script>
    <link rel="stylesheet" href="@Url.Content("~/Content/fancybox/helpers/jquery.fancybox-buttons.css?v=1.0.5")" type="text/css" />
    <script type="text/javascript" src="@Url.Content("~/Content/fancybox/helpers/jquery.fancybox-buttons.js?v=1.0.5")"></script>
}

But it is showing an error

The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_blanklayout.cshtml": "JavaScript".

1 个答案:

答案 0 :(得分:2)

在布局页面上,您需要指定呈现“JavaScript”部分的位置

_blanklayout.cshtml中的某处添加:

@RenderSection("JavaScript")