Wednesday 13 January 2021

MVC - jQuery - How to add ID to drop down list and access drop down list by ID

 

 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="button" onclick="DoSomething()"   value="Submit" />

@section Scripts{
    <script type="text/javascript">
        function DoSomething() {
            alert($("#myID option:selected").text())
        }
      
        $(document).ready(function () {
       
      
        });
    </script>
    }

No comments:

Post a Comment