Skip to content
Loading
How do I add a a dropdown menu in the default asp .net 3.1 razor templ

1 Reply

Know the answer? Post it — somebody with the same question will find it here.

  HomeController.cs 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6.   
  7. namespace WebApplication1.Controllers  
  8. {  
  9.     public class HomeController : Controller  
  10.     {  
  11.         public ActionResult Index()  
  12.         {  
  13.             return View();  
  14.         }  
  15.         public ActionResult GetMenus()  
  16.         {  
  17.             List menusList = new List() {  
  18.                 new SelectListItem { Text = "Menu 1", Value = "1" },  
  19.                  new SelectListItem { Text = "Menu 2", Value = "2" },  
  20.                   new SelectListItem { Text = "Menu 3", Value = "3" }  
  21.             }.ToList();  
  22.   
  23.             ViewBag.Menus = menusList;  
  24.             return PartialView("_Menus");  
  25.         }  
  26.     }  
  27. }  
Output-And Now, the dropdown menu displayed like this