Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net MVC5身份登记表上的路由问题_Asp.net_Asp.net Mvc_Asp.net Mvc Routing_Asp.net Identity - Fatal编程技术网

Asp.net MVC5身份登记表上的路由问题

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

我正在使用asp.net MVC 5和Identity v2。我的问题是,注册失败时被回调的URL有一个问题,因为它附加了length=7,这通常意味着路由有问题,我还没有解决这个问题

我的注册表单位于localhost:44300/en US/Account/register,如果您提交的表单返回无效的服务器端验证(例如,如果使用用户名),则该表单会将您重定向到localhost:44300/en US/Account/register?Length=7

这在寄存器方法中发生:

    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" }))