title: How To Call Controller from Layout Html.Partial
body: <p>I'm working with Asp.net MVC 4, engine razor.
  I am developing an application and the menu is dynamically created by the user's role</p>
  
  <p><strong>UPDATE</strong>
  In my application I need the user to enter their credentials with these recovered data on user role and build the dynamic menu for the role. 
  My main screen is:
  <img src="https://i.stack.imgur.com/LH6Az.png" alt="enter image description here"></p>
  
  <p>in my _Layout.cshtml I have this code:</p>
  
  <pre><code>@if (Request.IsAuthenticated){
          Html.Partial("Menu");
      } else { 
          &lt;div class="sectiontitle"&gt;&amp;nbsp;&lt;/div&gt;
      }
  </code></pre>
  
  <p>I create a base controller:</p>
  
  <pre><code>public class BaseController : Controller
  {
      public BaseController(){
          ViewBag.Menu = BuildMenu();
      }
  
      private IList&lt;Models.AdmMenu&gt; BuildMenu()
      {      
              IList&lt;Models.AdmMenu&gt; mmList = new List&lt;Models.AdmMenu&gt;(){
              new Models.AdmMenu(){ Id = 1, Name = "Home", ParentId = 0, SortOrder = 1} ,
              new Models.AdmMenu(){ Id = 2, Name = "Admin", ParentId = 0, SortOrder = 1},
              new Models.AdmMenu(){ Id = 3, Name = "Account", ParentId = 0, SortOrder = 1},
              .....
              .....
  </code></pre>
  
  <p>And in my controller raLoginController.cs I have this:</p>
  
  <pre><code>public class raLoginController : BaseController{                
      [HttpPost]
      public ActionResult Login(Models.AdmLogin login){
          if (ModelState.IsValid){
              Servicio.cSeReclamo Servicio = new Servicio.cSeReclamo(login.UserName, login.Password);
              if (Servicio.ValidarUsuario()){
                  string Mensaje = "";
                  Models.AdmUsuario oAdmUsuario = new Models.AdmUsuario();
                  oAdmUsuario.Au_codusuario = login.UserName;
                  Servicio.RetornaEntidad&lt;Models.AdmUsuario&gt;(ref Mensaje, "admsis.adm_usuario", oAdmUsuario.getPk(), oAdmUsuario);                                      
                  FormsAuthentication.SetAuthCookie(login.UserName, false);  
  
                  var ticket = new FormsAuthenticationTicket(1,
                      login.UserName,
                      DateTime.Now,
                      DateTime.Now.AddMinutes(30),
                      false,
                      LoadData(oAdmUsuario,Servicio.Pais(ref Mensaje))
                  );
  
                  string encTicket = FormsAuthentication.Encrypt(ticket);
                  HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
  
                  if (ticket.IsPersistent) {
                      faCookie.Expires = ticket.Expiration;
                  }
                  Response.Cookies.Add(faCookie);
                  return RedirectToAction("index", "raMainReclamo", new { area = "Reclamos"});
              }
          }
          return View(login);
      }
  </code></pre>
  
  <p>In Menu.cshtml (Partial View)</p>
  
  <pre><code> @{
      List&lt;Crd.Web.Models.AdmMenu&gt; menuList = ViewBag.Menu;       
  }
  &lt;div class="sectiontitle"&gt;     
  &lt;ul class="menu" id="header"&gt;  
      @foreach (var mp in menuList.Where(p =&gt; p.ParentId == 0))
      {    
          &lt;li&gt;&lt;a href="#"&gt;@mp.Name&lt;/a&gt; 
          @if (menuList.Count(p =&gt; p.ParentId == mp.Id) &gt; 0)
          {
              @:&lt;ul&gt;
          }          
          @RenderMenuItem(menuList, mp)       
          @if (menuList.Count(p =&gt; p.ParentId == mp.Id) &gt; 0)
          {
              @:&lt;/ul&gt;
          }       
          &lt;/li&gt;
      }
  &lt;/ul&gt;   
  &lt;/div&gt; 
  </code></pre>
  
  <p>But when I enter the credentials have the following error:
  <img src="https://i.stack.imgur.com/6IFOI.png" alt="enter image description here"></p>
  
  <p>menulist is equal a null, why? I am following the code step by step, enters BaseController and execute BuildMenu method... why null?
  I have this message:
  <img src="https://i.stack.imgur.com/Soq1u.png" alt="enter image description here"></p>
  
  <p>How to resolve this problem?</p>