ASP.NET MVC 2 DropDownList does not render

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

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; } } } 

DropDownList doesn't even appear in the DOM, and I don't understand what I'm doing wrong.

Projectscontroller

 namespace ProjectsPageMVC.Controllers { public class ProjectsController : MasterController { public ActionResult Index() { return View(); } } } 
+4
source share
2 answers

Edit

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

to

  <%=Html.DropDownList("navigationList") %> 
+7
source

Change the layout:

 <%= Html.DropDownList("navigationList", (SelectList)ViewData["navigationList"]); %> 
+2
source

Source: https://habr.com/ru/post/1304911/


All Articles