【发布时间】:2015-05-01 07:25:28
【问题描述】:
我在我的 asp.net mvc4 应用程序中使用 CaptchaMvc.Mvc4 1.5.0。 这是我的看法:
@using CaptchaMvc.HtmlHelpers;
@using CaptchaMvc;
@model Web.Models.Message
@using (Ajax.BeginForm("Contact", "Home", new AjaxOptions
{
HttpMethod = "post",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "Sent"
}
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
@Html.LabelFor(model => model.Name)
<div>
@Html.TextBoxFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
@Html.LabelFor(model => model.Email)
<div>
@Html.TextBoxFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
@Html.LabelFor(model => model.Message1)
<div>
@Html.TextBoxFor(model => model.Message1)
@Html.ValidationMessageFor(model => model.Message1)
</div>
@Html.MathCaptcha()
<input type="submit" value="Create" />
</fieldset>
<div id="Sent">
</div>
}
这是我的行动方法:
[HttpPost]
public ActionResult Contact(Message message)
{
if(this.IsCaptchaValid("error"))
if (ModelState.IsValid )
{
db.Messages.Add(message);
db.SaveChanges();
return RedirectToAction("SuccessfullySent");
}
ModelState.AddModelError("", "there is some error");
return View(message);
}
验证码输入有效时可以正常工作。 问题是当验证码无效时,整个视图都呈现在 id="Sent" 的 div 中。所以我在一页中呈现了两个消息视图。 如何防止它在 id="Sent" 的 div 中再次呈现整个视图?
【问题讨论】:
标签: asp.net ajax asp.net-mvc asp.net-mvc-4 captcha