Home MVC Pass List from DB to _Layout.cshtml
Reply: 0

MVC Pass List from DB to _Layout.cshtml

user2528 Published in March 24, 2018, 2:20 am

I am new to MVC and trying figure out how I would pass some data to the _Layout.cshtml view. This will be data from my database that will need to be displayed on every page.

The approach I am taking is through a partial view. Not sure if the is the best approach but it is resulting an error. Is there a better approach or how do I fix this error?

I have simplified my project to show the error I received with the partial view approach.

Error: The controller for path '/' was not found or does not implement IController.


<!DOCTYPE html>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>

@{Html.RenderAction("getMenuList", "MenuView"); }

<div class="container body-content">

@RenderSection("scripts", required: false)


@model System.Collections.Generic.List<PartialViewTest.Models.MenuItems>

    @foreach (var _Menu in Model)


namespace PartialViewTest.Controllers
    public class MenuController : Controller

        public PartialViewResult getMenuList()
            System.Collections.Generic.List<Models.MenuItems> _list;
            _list = new System.Collections.Generic.List<Models.MenuItems>
                new PartialViewTest.Models.MenuItems{ LinkName = "Google", LinkURL = "http://google.com"},
                new PartialViewTest.Models.MenuItems{ LinkName = "CNN", LinkURL = "http://cnn.com"}

            return PartialView("getMenuList", _list);

        // GET: Menu
        public ActionResult Index()
            return View();


namespace PartialViewTest.Models
    public class MenuItems
       public string LinkName { get; set; }
       public string LinkURL { get; set; }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299236 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO