jQuery验证:使用远程验证器
|
我正在尝试实现我们在这里可以看到的内容:
http://weblogs.asp.net/cibrax/archive/2008/08/01/combining-jquery-validation-with-asp-net-mvc.aspx
我遇到的问题是它不使用远程验证器。
<form action=\"<%=Url.Action(\"Register\", \"Home\")%>\" method=\"post\" id=\"form-sign-up\">
就我而言,每当我点击Submit时,它将发布到Register动作中-我似乎从未碰过Json验证器方法。实际上,我下载了示例,但远程帖子对我不起作用。远程部分是否可以在示例中为其他任何人使用?
有谁知道如何让他们工作或有更好的榜样?
基本上,我拥有的是模式弹出编辑表单。我想在发布到保存(或本例中为“1ѭ”)方法之前进行所有验证。
我只需要检查它是必需的,远程验证器就是检查它是否重复。在我的示例中,我错过了验证器,最终遇到了save方法。显然,我只想保存该字段,并且该字段不是重复的。
编辑0:
我正在使用MVC 2
<form action=\"/Region/Save\" method=\"post\" id=\"Form-AddRegion\">
<div class=\"editor-label\">
<%: Html.Label(\"Region:\") %>
<%: Html.TextBoxFor(model => model.Region, new { @class = \"edit required remote\"}) %>
</div>
<p>
<input type=\"submit\" value=\"Save\" />
<input type=\"button\" onClick=\"window.parent.CloseWindow();\" value=\"Cancel\" />
</p>
</form>
public ActionResult ValidateRegion(string name)
{
if (!something)
return Json(true, JsonRequestBehavior.AllowGet);
return Json(false, JsonRequestBehavior.AllowGet);
}
<script type=\"text/javascript\">
$(document).ready(function () {
alert(\'jQuery is referenced properly\');
$(\"#Form-AddRegion\").validate({
rules:
{
//rules each for specified input-id
Region:
{
required: true,
remote: \'<%=Url.Action(\"ValidateRegion\",\"Region\") %>\'
}
},
messages:
{
Region:
{
required: \"Please provide a Region\",
remote: jQuery.format(\"{0} is already in use\")
}
}
});
});
</script>
所以问题在于,在提交时,我总是在验证器ValidateRegion
之前发布到保存方法/Region/Save
!我是否错过ѭ5的路线?
我需要知道javascript代码何时发布/进入验证器方法?我会假设提交,但似乎从未收到过!!
当人们不读您的问题并将您指向主要文档参考时,确实很烦人,很有趣,我已经去过那里。
没有找到相关结果
已邀请:
1 个回复
靛新比比催
永远不会提交 将jquery validate连接到onsubmit是通过validate()函数完成的,需要在准备好文档时完成 还有一件事情,所有输入的NEEDS name属性都可以被验证 有关更多文档和大量示例的信息,请参见http://docs.jquery.com/Plugins/Validation/ 编辑 这是您在jsFiddle中的代码: http://jsfiddle.net/fzf3q/1/ 它只能在运行时才建议您确保在其中包含了validate函数: