[英]Update using ajax in asp.net 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)中。
好吧,最明顯的問題是,您是否將腳本添加到了要執行此操作的頁面中? 其次,如果您要發布到HTTPS(是,對嗎?),您的腳本也必須是HTTPS,否則會出現安全錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.