Reputation: 36264
I created a form that posts and gets results through jQuery AJAX. Now I need to put some validation stuff on it. I wonder how to do it. Should I use jQuery validation plugin? If I use it and if I'm guessing right - there is no need to decorate the model with DataAnnotations attributes, they no longer gonna make any sense, right?
So basically that I'm saying: I use a normal html form Html.BeginForm()
, not an AJAX form, then I override the form's submit() function
$("form[action$='UpdateCalendarForm']").submit(function ()
{
$.ajax({
url: $(this).attr("action"),
contentType: 'application/json; charset=utf-8',
type: "POST",
data: JSON.stringify(calendarData),
dataType: "json",
success: updateCalendarCallback
});
return false; // it wouldn't actually rerender the page
});
function updateCalendarCallback(result){
// And here I just do something on the page
}
What's the best way to add some validation here without Ajax helper methods (but using jQuery) and DataAnnotations attributes on the Model properties.
Upvotes: 0
Views: 630
Reputation: 39501
Brad Wilson had great video on mvcConf about validation. Here's everything you will need to know to start implementing custom validation on mvc3
Upvotes: 2