@using (Ajax.BeginForm("Register","Account",
new AjaxOptions
{
HttpMethod="POST",
UpdateTargetId="Done",
InsertionMode=InsertionMode.Replace,
OnSuccess="SucceedCreatedNewAcc"
}
))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary()
//Fill in the form
<div id="Done"></div>
}
我的register
方法
[HttpPost]
[Authorize]
[ValidateAntiForgeryToken]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
try
{
WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
return PartialView(model);
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
}
}
return PartialView();
}
我的 JS 片段SucceedCreatedNewAcc
function SucceedCreatedNewAcc()
{
$( "#Done" ).html( "A new account has been created" );
}
我有2个小问题
我不知道我在
SucceedCreatedNewAcc
重置我曾经在上面填写的所有表单字段中插入了什么。我想清空所有这些。如何检索成功创建的帐户的用户名,以便我可以将其插入
SucceedCreatedNewAcc
以使我的html
文本更有意义,即$( "#Done" ).html( "A new account @username has been created" );