1.10.4.Implementing Client-side Validation
@section Scripts
{
@Scripts.Render("~/bundles/jqueryval");
<script>
$(document).ready(function () {
$.validator.addMethod("validationCustomer", function () {
return vm.customerId && vm.customerId !== 0;
}, "Please select a valid customer");
$("#newRental").validate({
submitHandler: function () {
$.ajax({
url: "/api/newRental",
method: "post",
data: vm
})
.done(function () {
toastr.success("Rental successfully recorded");
})
.fail(function () {
toastr.error("Something unexpected happened");
});
}Last updated