我在我的主布局视图(A)中定义了一个部分视图(强类型)a1。然后我有一个子视图(B),它本身是一个布局视图,但嵌套在主布局视图中。然后我有一个页面视图,从中调用并加载模型数据。请问如何将此数据中的数据传递到嵌套在主布局视图中的部分视图?
Shared/_Layout.cshtml(主布局)
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<header>
@RenderPage("~/Views/Shared/PartialViews/Shared/_headerView.cshtml")
</header>
</body>
</html>
Shared/_Layout.cshtml(子布局)
@{
ViewBag.Title = "Blog";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@if (IsSectionDefined("BlogHeaderContent"))
{
<div class="blogHeader">
@RenderSection("BlogHeaderContent", required: false)
</div>
}
@RenderBody()
视图/博客/blogindex.cshtml(博客视图)
@model MyModels.Blog
@{
ViewBag.Title = " See Blog";
}
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Blog</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Body)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Body)
@Html.ValidationMessageFor(model => model.Body)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}