开发者

jQuery Ajax validation and DataAnnotations attributes

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: updateCalenda开发者_JAVA技巧rCallback
           });
    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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜