Upon submitting the update form, it is necessary to verify that the Status value is not less than zero. This specific part of the form is as follows:
<div class="form-group">
@Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Status, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
</div>
</div>
If using JavaScript to submit the entire form, how can I retrieve this specific value?
$(document).ready(function () {
$("#btnUpdateProduct").click(function () {
// Some where here or after var myformdata = $("#myForm").serialize(); I must check if
// Value of @Html.LabelFor(model => model.Status .....
var myformdata = $("#myForm").serialize();
$.ajax({
type: "POST",
url: "/Home/EditProduct",
data: myformdata,
success: function () {
$("#updateModal").modal("hide");
location.reload();
}
})
})
})
Below is the complete View Form:
@model Products.Models.Product
<div>
<form id="myForm">
<div class="form-horizontal">
<h4>Product</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ProductId)
@Html.HiddenFor(model => model.CountryId)
@Html.HiddenFor(model => model.ModelId)
<div class="form-group">
@Html.LabelFor(model => model.ProductName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProductName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Model, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Model, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Model, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Model, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Status, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" id="btnUpdateProduct"/>
</div>
</div>
</div>
Thank you!