0

我有一套包含多个 MVC3 Web 应用程序的套件,所有这些应用程序都引用了一个通用的 Core.dll。我使用 RazorGenerator 编译了公共视图,订阅站点从预编译的 .dll 中找到相关视图没有任何问题。

我正在尝试对布局页面执行相同的操作,因为这在所有站点中也很常见,除了特定于该特定站点的一两个 div。这也可以正常工作,只要这样做就可以提供 _layout 视图:

@{
     Layout = "~/Views/Shared/_Layout.cshtml";
}

但是,要在布局中填充特定站点的 div,我希望在特定站点中有一个部分视图,并使用 JQuery 在 _layout 中设置占位符 div 的 HTML。就像是:

@{
     Layout = "~/Views/Shared/_Layout.cshtml";
}

//Have a hidden div containing the partial view that sits in the specific site
<div id="SiteSpecificStuff" style="display:none">
    @Html.Partial("_SiteSpecificStuff", model)
</div>

// Use jQuery to populate the html of the placeholding div on the _Layout 
// with that of the partial view
<script type="text/javascript">

    $(document).ready(function () {
          $("#divPlaceHolderOnLayout")
                        .html($("SiteSpecificStuff").html());
    });

</script>

我已经尝试过了,但 _ViewStart 不会在每个帖子上重新触发。这可能使用不同的方法吗?

4

1 回答 1

0

我想你正在寻找这个:

@RenderSection("YouSection", required: false)
于 2013-07-18T13:53:56.747 回答