Wednesday 6 January 2021

MVC - jQuery - how to add new empty line to drop down list using java script

 

 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() {
            $("#myID").prepend("<option value=''></option>");
        }
    </script>
    }
 

No comments:

Post a Comment