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

    Reset DropdownlistFor in MVC5

    I have one simple form with 1 dropdownlist and 1 button called Reset.
    I have bind dropdown through model.
    Now, I want to reset dropdownlist selected value to 0 on click on Reset button.
    Below is the code I am using right now.

    @Html.DropDownListFor(Model => Model.Month, ViewData["Month"] as List<SelectListItem>, "--Select--", new { @class = "selectpicker" })

    <input type="reset" value="Clear" id="btnClear" class="btn btn-default" />

    I tried with below solutions, but not working. Please help.

    $("#btnClear").click(function () {
    //$("#Month").val()= "01";
    //$('#Month option:selected').val = "01";
    //$('#Month').get(0).selectedIndex = 0;
  • #768215
    The below code will work

    $('#Month')[0].selectedIndex = 0

  • Sign In to post your comments