开发者

Can I use a Controller to give information to _Layout.cshtml?

开发者 https://www.devze.com 2023-01-30 10:14 出处:网络
Basically, my _Layout.cshtml file is my MasterPage type V开发者_开发技巧iew. In it I\'m designing the common look that will be shared across all Views.

Basically, my _Layout.cshtml file is my MasterPage type V开发者_开发技巧iew.

In it I'm designing the common look that will be shared across all Views.

I'm trying to load a left sidebar with a listing of all Categories in my database. For this purpose I've created a ViewModel called SidebarNavigation.cs

In my _Layout.cshtml I'd like to do something like:

<div id="leftnavigationbar">            
    @Html.Partial("_SideBarMenu", model)
</div>

But it seems that _Layout.cshtml doesn't actually use a Model up top in the page.

Any suggestions?


Just like in the aspx view engine the layout page "receives" the same model as the content page. For additional view data like this you should add it to the ViewData dictionary

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号