【发布时间】:2011-04-11 16:40:41
【问题描述】:
我创建了一个通过 jQuery AJAX 发布和获取结果的表单。现在我需要在上面放一些验证的东西。我想知道怎么做。我应该使用 jQuery 验证插件吗?如果我使用它并且我猜对了——不需要用 DataAnnotations 属性来装饰模型,它们就不再有意义了,对吧?
所以基本上我的意思是:我使用普通的 html 表单 Html.BeginForm(),而不是 AJAX 表单,然后我覆盖了表单的 submit() 函数
$("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
}
在没有 Ajax 辅助方法(但使用 jQuery)和 Model 属性上的 DataAnnotations 属性的情况下,在此处添加一些验证的最佳方法是什么。
【问题讨论】:
标签: jquery validation asp.net-mvc-3