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

    How to set selected value in dropdown in mvc

    Hi i am bindiing dropdown with hardcoded value . Now i want to set value=M on searching button click using viewbag. How can i set in view .Thanks in advance

    @Html.DropDownListFor(m => m.Gender, new List<SelectListItem>
    { new SelectListItem{Text="Male", Value="M"},
    new SelectListItem{Text="Female", Value="F"}}, "Please select")
  • #769512
    @Html.DropDownListFor(m => m.Gender, new List<SelectListItem>
    { new SelectListItem{Text="Male", Value="M"},
    new SelectListItem{Text="Female", Value="F"}}, "M")

    If you want to select by default as "M", then just replace with "Please select" to "M". So, by default it will select as M.

    Regards,
    V.M. Damodharan
    "Your talent will be worthless, when you have fear and tension."


  • Sign In to post your comments