Monday, 11 January 2021

MVC - jQuery - select specified item in drop down list using jQuery (in seconds!)

 Watch this example on YouTube


 

 

 @model WebApplication1.Models.OrderCustomClass




@using (Html.BeginForm("Index", "Home"))
{
    @Html.DropDownListFor(x=>x.or.ProductID, new SelectList(Model.prod,"ProductID", "Name"), new { @id = "myID" })

    
}
<input type="submit" onclick="DoSomething()" value="Add empty value" />

@section Scripts{
    <script type="text/javascript">
        function DoSomething() {
            var myDDL = $('#myID');
            myDDL[0].selectedIndex = 2;

        }
    </script>
    }
 

No comments:

Post a Comment