You must Sign In to post a response.
  • Category: ASP.Net MVC

    What is the syntax to add dropdown list in Asp.net MVC (NOT RAZOR)

    I add ck editor in asp.net MVC as:

    <%:Html.TextAreaFor(x => x.Text, new {id = "my-textarea", @class = "ckeditor" }) %>

    what is the syntax to add DROPDOWNLIST IN ASP.NET MVC( NOT RAZOR)
  • #762015
    Hello sp,

    You can refer the below code :

    <select id="User_State" name="User.State"><option value="0">Nirav</option>
    <option value="1">Sridhar</option>
    <option value="2">Kumar</option>
    </select>


    @Html.DropDownListFor(model => model.User.State, new SelectList(
    new List<Object>{
    new { value = 0 , text = "Nirav" },
    new { value = 1 , text = "Sridhar" },
    new { value = 2 , text = "Kumar"}
    },
    "value",
    "text",
    2))


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762102
    Hi

    For adding dropdownlist in asp.net mvc go through below links which shows you in different ways using collections and helper methods.

    http://codeclimber.net.nz/archive/2009/08/05/how-to-create-a-dropdownlist-with-asp.net-mvc.aspx

    http://www.asp.net/mvc/overview/older-versions/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with-aspnet-mvc

    http://www.codeproject.com/Articles/662968/Creating-a-DropDownList-for-Enums-in-ASP-NET-MVC

    Regards

    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.


Sign In to post your comments