Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 2 DropDownList not rendering

so I don't understand what I am doing wrong here. I want to populate a DropDownList inside the master page of my ASP.NET MVC 2 app.

Projects.Master

<div id="supaDiv" class="mainNav">
 <% Html.DropDownList("navigationList"); %>
</div>

MasterController.cs

namespace ProjectsPageMVC.Controllers.Abstracts
{
    public abstract class MasterController : Controller
    {
        public MasterController()
        {
          List<SelectListItem> naviList = new List<SelectListItem>();

          naviList.Add(new SelectListItem
          {
           Selected = true,
           Text = "AdvanceWeb",
           Value = "http://4168web/advanceweb/"
          });

          naviList.Add(new SelectListItem
          {
           Selected = false,
           Text = " :: AdvanceWeb Admin",
           Value = "http://4168web/advanceweb/admin/admindefault.aspx"
          });

          ViewData["navigationList"] = naviList;
        }
    }
}

The DropDownList is not even showing up in the DOM and I am at a loss as to what I am doing wrong.

ProjectsController

namespace ProjectsPageMVC.Controllers
{
    public class ProjectsController : MasterController
    {
        public ActionResult Index()
        {
            return View();
        }
    }
}
like image 466
Tomasz Iniewicz Avatar asked Jan 23 '23 09:01

Tomasz Iniewicz


2 Answers

Change

<% Html.DropDownList("navigationList"); %>

to

 <%=Html.DropDownList("navigationList") %>
like image 136
mxmissile Avatar answered Jan 28 '23 07:01

mxmissile


Change your markup:

<%= Html.DropDownList("navigationList", (SelectList)ViewData["navigationList"]); %>
like image 44
Dave Swersky Avatar answered Jan 28 '23 06:01

Dave Swersky