title: Load menu in LayoutPage from database dynamically in database in Asp.net MVC5?
body: <p>I want to load menu dynamically in layout page in MVC.</p>
  
  <p>I have created Viewcode, model for menu and menuitems. Now what I want is to load the menus dynamically. It has to retrieve data from database and load in Layout page.</p>
  
  <p><strong>My model</strong></p>
  
  <p><strong>Menu Model</strong></p>
  
  <pre><code>public Menu()
  {
      MenuItems = new List&lt;MenuItem&gt;();
  }
  
  public int Id { get; set; }
  public string Name { get; set; }
  public List&lt;MenuItem&gt; MenuItems { get; set; }
  </code></pre>
  
  <p><strong>My model MenuItem</strong></p>
  
  <pre><code>public class MenuItem
  {
  public int Id { get; set; }
  public int UserName { get; set; }
  public string Name { get; set; }
  public string ActionName { get; set; }
  public string ControllerName { get; set; }
  public string Url { get; set; }
  public Menu ParentMenu { get; set; }
  }
  </code></pre>
  
  <p><strong>My Controller Code</strong></p>
  
  <pre><code>  public ActionResult Index()
      {
          var menu = new Menu();
          menu.Name = "Main Menu";
          var query = db.ApplicationNames.Select(e =&gt; new { 
            UID=  e.UID,
               e.ApplicationName1
          }).FirstOrDefault();
          var uid = query.UID.ToString();
          var name = query.ApplicationName1;
  
     var items = new List&lt;MenuItem&gt;() { new MenuItem { Name = "FirstMenu", ControllerName = uid, ActionName = name }};
          menu.MenuItems = items;
          return PartialView("_MenuLayout",menu);
      }
  </code></pre>
  
  <p><strong>My partial view  _MenuLayout</strong></p>
  
  <pre><code> @model List&lt;DynamicMenuLoading.Models.Menu&gt;
          &lt;ul&gt;
               &lt;li&gt;
                  &lt;a href="#"&gt;
                     &lt;span&gt;@Model.Name&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;ul&gt;
                      @foreach (var item in Model.MenuItems)
                      {
                          &lt;li&gt;&lt;a href="@Url.Action(@item.ActionName , @item.ControllerName )"&gt;&lt;i class="fa fa-circle-o"&gt;&lt;/i&gt;@item.Name&lt;/a&gt;&lt;/li&gt;
                      }
                  &lt;/ul&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
  </code></pre>
  
  <p><strong>My Layout Page</strong></p>
  
  <pre><code>         &lt;nav id="mainNavigation"&gt;
             @Html.Partial("_MenuLayout")
           &lt;/nav&gt;
  </code></pre>
  
  <p><strong>My table name ApplicationName</strong></p>
  
  <blockquote>
    <p>UID ApplicationName</p>
    
    <p>1      EMPLOYEE</p>
    
    <p>2      CUSTOMER</p>
    
    <p>3      CITY</p>
    
    <p>4      STATE</p>
    
    <p>5      COUNTRY</p>
  </blockquote>
  
  <p>While I am trying to run my project I am getting this error:</p>
  
  <blockquote>
    <p>e:\Task
    Tried\DynamicMenuLoading\DynamicMenuLoading\Views\Shared_MenuLayout.cshtml(8):
    error CS1502: The best overloaded method match for
    'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)'
    has some invalid arguments</p>
  </blockquote>
  
  <p>Can anyone tell me what mistake I did? Can anyone understand my issue and give solution to my problem?</p>