How to give shared layout a model in Razor MVC?
问题 I'm trying to give a model to the shared layout so the menu links are created dynamically from a database. Any ideas where I should start? I am looking for maybe tutorials of how to use inheritance to do this? 回答1: You could do this: Model public partial class Menu { public String[] items; public Menu(String[] items) { this.items = items; } } View (_Menu) @model YourMVC.Models.Menu <ul> @foreach (String item in Model.items) { <li>@item</li> } </ul> Place this in _Layout @Html.Action("_Menu",