In my ASP.NET MVC project, create view consist of a main view and another couple of partial views.
So in one partial view, there is a combo box, I want to restrict it without selecting a value, so the user cannot submit the form.
I tried writing a javascript within that partial view, but it won't work. So want to know is there are any other ways to do this restriction?
<div class="form-group row">
@Html.Label("Select the Approver", htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-sm-8">
@Html.DropDownListFor(model => model.Approver_Id, new List<SelectListItem>(), new { @id = "ddlEmployees", @class = "js-dropdown" })
@Html.ValidationMessageFor(model => model.Approver_Id, "", new { @class = "text-danger" })
</div>
</div>
I cant use it on the model as required because some options in this combo box get hidden before submitting the form. So If I apply required to the model, the form does not get submitted for those options also.
Any suggestions would help me. :)
if you don't want to handle this server-side you can do it client-side by JS.
$('#submitDemo').click( if(!$("drpval").val()>0) return false; );