I declare a class Name.cs to store some data:
namespace myproj.Data
{
public class Name
{
public string[] items = new string[] {"item1",
"item2", "item3"}
}
}
How can I use it in the _Layout.cshtml so that I can do something like:
@foreach (var item in Name.items)
{
<div id="@item"></div>
}
_Layout. If you need something passed to it to manipulate the output I would either pass it from the controller usingViewBagor I would have aViewComponentto do the work and output to the view as needed._Layout.cshtml:@model myproj.Models.SidebarData<partial name="_Sidebar.cshtml" model="Model"/>return View()toreturn View("Index", new myproj.Models.SidebarData())in every controller.