重定向到没有查询字符串的路由

时间:2014-02-09 10:00:46

标签: asp.net asp.net-mvc-4 redirect routing asp.net-mvc-routing

如何在不在我的网址上获取查询字符串的情况下重定向到路由?

路线配置......

routes.MapRoute(
    name: "ApplicationStatus",
    url: "join/ApplicationStatus/{applicationKey}/{characterId}",
    defaults: new { controller = "Join", action = "ApplicationStatus" }
);

要重定向的控制器代码......

    return RedirectToAction("ApplicationStatus", new { 
        applicationKey = applicationKey,
        characterId =_sm.JoinState.CharacterId
    });

控制器动作方法......

public ActionResult ApplicationStatus(string applicationKey, long characterId)
{
    return View(new ApplicationStatus());
}

因此,当我从控制器重定向时,浏览器会给我以下网址...

http://localhost/TestApp/Join/ApplicationStatus?applicationKey=xxxxxxx&characterId=nnnnnnnn

但我想得到这个......

http://localhost/TestApp/Join/ApplicationStatus/xxxxxxx/nnnnnnnn

提前致谢。

1 个答案:

答案 0 :(得分:2)

您应该使用RedirectToRoute

试试这个。

    return RedirectToRoute("ApplicationStatus", new { 
        applicationKey = applicationKey,
        characterId =_sm.JoinState.CharacterId
    });