且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将数据传递到布局页

更新时间:2023-12-03 16:31:16

确定,因为你希望它设置一次,您可以利用局部视图。不过根据你的需要,你需要有一些局部视图(可能是不理想的,如果部分将要分散在_layout页)

OK since you want this to be set once you can make use of a partial view. However depending on your needs you will need to have several partial views (may be not ideal if sections are going to be scattered across the _layout page)

你的部分观点看起来像

@model KarateAqua.schoolModel

<div class="bottom_logo">
<a href="/"><span class="inv">@Model.schoolName</span>
</div>

控制器

public class SchoolController : Controller
{
     public ActionResult Index()
     {
          //get schoolModel  
          return PartialView(schoolModel);
     }
}

在你_layout.cshtml地方这条线,你想拥有的局部视图插入

in your _layout.cshtml place this line where you want to have the partial view to be inserted

@Html.Action("Index","School")