Asp.net MVC5身份登记表上的路由问题
我正在使用asp.net MVC 5和Identity v2。我的问题是,注册失败时被回调的URL有一个问题,因为它附加了length=7,这通常意味着路由有问题,我还没有解决这个问题 我的注册表单位于localhost:44300/en US/Account/register,如果您提交的表单返回无效的服务器端验证(例如,如果使用用户名),则该表单会将您重定向到localhost:44300/en US/Account/register?Length=7 这在寄存器方法中发生:Asp.net MVC5身份登记表上的路由问题,asp.net,asp.net-mvc,asp.net-mvc-routing,asp.net-identity,Asp.net,Asp.net Mvc,Asp.net Mvc Routing,Asp.net Identity,我正在使用asp.net MVC 5和Identity v2。我的问题是,注册失败时被回调的URL有一个问题,因为它附加了length=7,这通常意味着路由有问题,我还没有解决这个问题 我的注册表单位于localhost:44300/en US/Account/register,如果您提交的表单返回无效的服务器端验证(例如,如果使用用户名),则该表单会将您重定向到localhost:44300/en US/Account/register?Length=7 这在寄存器方法中发生: pub
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: true);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// The following line seems to call the URL with ?length=7
return View(model);
}
编辑:
我的表单标签是:
@using (Ajax.BeginForm("Register", "Account", new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
LoadingElementId = "loader",
OnSuccess = "OnSuccess",
OnFailure = "OnFailure "
}, new { @id = "localForm" }))
我不确定问题出在哪里,也没有引起任何问题,但如果问题明显出在哪里,我很想弄清真相 您是否绝对确定仅在执行返回视图(模型)后添加参数?因为通常情况下,这会将您返回到相同的url 表单的操作url很可能是错误的,但由于您的
重定向到操作
,它会忽略这一点
如果是这样,请检查您的
BeginForm
参数,并尝试为RouteValueDictionary routeValues
设置null
,好的,我修复了问题,我丢失了route dictionary的值:
@using (Ajax.BeginForm("Register", "Account", null, new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
LoadingElementId = "loader",
OnSuccess = "OnSuccess",
OnFailure = "OnFailure "
}, new { @id = "localForm" }))
@using (Ajax.BeginForm("Register", "Account", null, new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
LoadingElementId = "loader",
OnSuccess = "OnSuccess",
OnFailure = "OnFailure "
}, new { @id = "localForm" }))