I have one form and in that one dropdown is in disabled status as per below :
<div >
<label asp-for="ItemEditModel.ProjectJobId" ></label>
<div >
<select asp-for="ItemEditModel.ProjectJobId"
asp-items="Model.ProjectJobList" disabled></select>
</div>
<span asp-validation-for="ItemEditModel.ProjectJobId"></span>
</div>
Now when we submit form then this field's value is not coming as it is in disabled state so.
Any idea how can I get this fields value when we submit form.
CodePudding user response:
Use Readonly Attribute instead of disabled
CodePudding user response:
You can try to use route parameter:
<form method="post" asp-route-ItemEditModel.ProjectJobId=@Model.ItemEditModel.ProjectJobId>
...
</form>
Or you can try to remove disabled
before form submitting:
<form id="myForm" method="post">
<div >
<label asp-for="ItemEditModel.ProjectJobId" ></label>
<div >
<select asp-for="ItemEditModel.ProjectJobId"
asp-items="Model.ProjectJobList" disabled></select>
</div>
<span asp-validation-for="ItemEditModel.ProjectJobId"></span>
</div>
<input type="submit" value="submit"/>
</form>
<script>
$('#myForm').submit(function () {
$("#ItemEditModel_ProjectJobId").removeAttr("disabled");
return true; // return false to cancel form action
});
</script>
Or you can add a hidden input to bind ItemEditModel.ProjectJobId
:
<form method="post">
<input hidden asp-for="ItemEditModel.ProjectJobId" />
...
</form>