Answer the question
In order to leave comments, you need to log in
How to pass data for strongly typed partial view or for _Layout.cshtml?
Hello! On the site, I use a strongly typed partial view for navigation (navigation is rendered on all pages). I use master pages.
_Layout.cshtml
<body>
@{Html.RenderPartial("_Navigation");}
@RenderBody()
<body/>
@model IEnumerable<ProgramManager.Models.Category>
<div class="list">
@foreach (var item in Model) {
<div class="list-item">
@Html.ActionLink(item.Name, "Item", "Category", new { id = item.Id})
</div>
}
</div>
Answer the question
In order to leave comments, you need to log in
Good afternoon!
By using
you simply display the view.
To pass the model to the view, you need to form this model. It is better to form the model in the action method , for example, like this:
[HttpGet]
public ActionResult Navigation()
{
List<MyClass> classes = new List<MyClass>();
classes.Add(new MyClass() { Id = 1, Name = "item 1" });
classes.Add(new MyClass() { Id = 2, Name = "item 2" });
classes.Add(new MyClass() { Id = 3, Name = "item 3" });
return View("_Navigation", classes);
}
Or is it possible to somehow pass it to _Layout.cshtml? then it will be globaldidn't understand.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question