我想實現什麼,我們可以在這裏看到: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