我想实现什么,我们可以在这里看到:jQuery的valiation:使用远程验证
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">
在我而言,每次我点击提交,其张贴到注册行动 - 我似乎从来没有击中JSON验证方法。事实上,我下载了示例,远程帖子不适合我。远程部分是否在样本中为其他人工作?
有谁知道如何让他们的工作或有一个更好的例子吗?
基本上我有是一个模式弹出编辑表单。我想发布到保存(或在这种情况下Register
)方法之前做的所有验证。
我只需要检查是必要的,远程验证是检查它是否是重复的。在我的例子中,我错过了验证器并最终进入了保存方法。很明显,我只想保存字段是否填写,而不是重复。
编辑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>
所以问题是,在提交,我一直张贴到保存方法/Region/Save
验证ValidateRegion
之前!我错过了global.asax.cs
的路线吗?
我需要知道什么时候的JavaScript代码后/进入验证方法?我会假设提交,但它似乎永远不会被调用!?
当人们没有阅读你的问题,并指出你在主要的文档参考中,肯定是讨厌的,有趣的是,我已经在那里。
你使用的是什么版本的mvc? PLZ提供一点代码 – 2011-04-19 07:44:26