So I have a page that have a few forms on it and one of those forms is a one for addresses which has three functions. Save as new, Update and Delete. I want to use form.submit() to fire the MVC validation on the client and server side but I dont want the entire page refresh.
So this is what I want to use the simple form.submit() to gather the elements and send it to the ASP.net MVC controller as a model and handle the validation based on the attributes I have on the model and use a callback to handle a JSON response to update only the affected area.
I know I could use jQuery to create an AJAX post request but I would have to handle everything, i.e. bind to the viewmodel, validation and create the request itself. Is there anyway I can get the best of both methods?
Also do not forget in Post Method in Controller to check
because client side validation will not validate hidden fields also if you will use ctr+shift+i in any browser and you will delete an
@Html.EditorFor(model => model.Price)
client validation will not validate this attribute.In MVC, once you validate Model data using DataAnnotations attributes you have already done with server side validation and then you can use
jQuery.validation library
to validate on client side.Here you can use Ajax.BeginForm post where you utilize DataAnnotations validation with ajax post.
DataAnnotations attributes
jQuery.validation library
Form with validation
Resource : http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-validation-to-the-model