我正在使用Ajax.BeginForm创建一个表单但是当我点击提交按钮时没有任何反应。我查看调试器工具栏中的网络选项卡,没有触发请求,并且javascript控制台中没有错误。我正在使用jquery不显眼的验证。
这是我的部分视图代码:
@using (Ajax.BeginForm("CreateUser", "Account", new AjaxOptions()
{
HttpMethod = "Post",
UpdateTargetId = "divCreateUser",
InsertionMode = InsertionMode.Replace,
OnSuccess = "CreateUserFormOnSuccess(response)"
}))
{
<div class="modal-body">
<fieldset>
<ol>
<li>
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName)
</li>
<li>
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password)
</li>
<li>
@Html.LabelFor(m => m.ConfirmPassword)
@Html.PasswordFor(m => m.ConfirmPassword)
</li>
</ol>
@*Html.Captcha("Inceacra alta imagine", "Introduceti textul pe care il vedeti in imagine:", 5, "Obligatoriu")*@
</fieldset>
</div>
<div class="modal-footer">
<a href="#" class="btn" onclick="$('#divCreateUser').modal('hide')">Anuleaza</a>
<input type="submit" value="Salveaza" class="btn btn-primary"/>
</div>
}
以下是我的行动:
[HttpGet]
public ActionResult CreateUser()
{
return View();
}
[HttpPost]
//[CaptchaVerify("Captcha introdus nu este valid")]
public ActionResult CreateUser(RegisterModel model)
{
if (ModelState.IsValid)
{
try
{
string token = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, null, true);
_emailRepository.SendConfirmationEmail(model.UserName, Url.Action("Confirm", new { id = token }));
return Json(new { result = true });
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
}
}
return View(model);
}
以下是模型:
public class RegisterModel
{
[Required]
[Display(Name = "Email")]
[EmailAddress]
public string UserName { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}