嗨,有人可以告訴我這個問題,請及時解決。更新在asp.net中使用ajax mvc
我想使用ajax更新頁面的一部分,我正在使用新的mvc項目附帶的基本代碼。
登錄頁有這樣的:
<span id="error"/>
@using (Ajax.BeginForm("LogOn", "Account", new AjaxOptions { UpdateTargetId="error"})) {
<div>
<fieldset>
<legend>Account Information</legend>
<div class="editor-label">
@Html.LabelFor(m => m.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.UserName)
@Html.ValidationMessageFor(m => m.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.Password)
@Html.ValidationMessageFor(m => m.Password)
</div>
<div class="editor-label">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
<p>
<input type="submit" value="Log On" />
</p>
</fieldset>
</div>
}
和控制器,像這樣:
[HttpPost]
public string LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl))
{
Redirect(returnUrl);
}
else
{
RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
return "The user name or password provided is incorrect.";
}
基本上我做的是內嵌登錄表單到一個模式彈出。 如果輸入的用戶憑證失敗我希望在模式彈出窗口中顯示錯誤,而不是進入另一頁面。
上面的代碼只是創建一個空白頁面,文本爲「提供的用戶名或密碼不正確」。我需要它在模式對話框(jQuery)中顯示。
你能告訴我們LogonModel?我假設它只是用戶名,密碼和RememberMe,但有沒有使用任何DataAnnotations?可能的話,如果你正在檢查ModelState。 – 2010-12-20 17:15:18
logonModel是一個帶有新的mvc項目的包裝盒 – raklos 2010-12-20 18:59:50