i'm an mvc newbie.
What i'm trying to do is to load menu from database and display it in partial view. This partial view will be called from _layout view.
Home Controller
in Home controller i add an action called "_MainMenu"
public class HomeController : Controller
{
mrpDatabase _db = new mrpDatabase();
public ActionResult _MainMenu()
{
return PartialView("_MainMenu", _db.menu.ToList());
}
....
}
PartialView
this is my _MainMenu PartialView
@model IEnumerable<appMRP.Models.menu>
<ul id="menu">
@foreach (var item in Model)
{
<li>@item.menu1</li>
}
</ul>
Layout Page
this partial menu is displayed in my _Layout.cshtml like this
<nav>
@Html.Partial("_MainMenu")
</nav>
when i run this. i got error "NullReferenceException was unhandled by user code. Object reference not set to an instance of an object"
seems the "Model" in my _MainMenu is null
what did i do wrong ?
thank you