0

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.

1 Answer 1

2

Brad Wilson had great video on mvcConf about validation. Here's everything you will need to know to start implementing custom validation on mvc3

Sign up to request clarification or add additional context in comments.

2 Comments

I don't need custom validation functionality (at least yet). I have a property in my model decorated with RequiredAttribute, and it doesn't work, because I'm using jQuery ajax. How to force client validation in this case?
That was my bad. I missed jquery.validate.min.js and jquery.validate.unobtrusive.min.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.