locked
How to create a dropdownlist in ASP.net MVC View. RRS feed

  • Question

  • HI,

    How to create a dropdownlist in ASP.net MVC View.

    I am using somthing like this

    <% using (Html.BeginForm()) { %>
        <%= Html.DropDownList(“lstProducts”, new SelectList((IEnumerable)ViewData["ProductList"], “Name”)) %>
        <input type=”submit” value=”Submit” />

    <% } %>

    where ProductList is a List<> that is fetched through LINQ from the tables and "Name" is the Coloumn Name which will show in DropDownList.

    My View Page is Something like this......

    @{

    ViewBag.Title = "Selector";

    }

    <

    h2>This is Selector Page</h2>

    i am using it but when i m seeing my application in running mode so its not showing anything...

    plz tell me where i am wrong and where this code should use in View...

    Thanks in advance!!

     

    Friday, March 4, 2011 8:18 AM

All replies

  • Hi Max,

    Are you certain that the List<Products> is being populated in your model or controller to be sent to the page? Also, are you sending the the ProductList to your view from your controller?


    Ankit
    Wednesday, March 9, 2011 4:51 PM
  • please do consult with microsoft.
    Sunday, March 13, 2011 12:52 PM