我正在呼叫RedirectToAction
,但它无法正常工作。
我希望生成的网址如下所示:
https://localhost:44301/ManageSpaces/123/overview
但它看起来像这样,并且缺少URL的操作部分:
https://localhost:44301/ManageSpaces/123
这是我的RedirectToAction
电话。
return RedirectToAction("overview", new RouteValueDictionary(
new {controller = "ManageSpaces", action = "overview", id = 123}));
以下是RouteConfig
中我的路线:
routes.MapRoute("ManageSpaces",
"ManageSpaces/{id}/{action}",
new { controller = "ManageSpaces", action = "overview"},
new { id = @"\d+" } //The regular expression \d+ matches one or more integers
);
答案 0 :(得分:1)
也许是采取默认路线。重命名,删除或注释掉默认路由以查看是否有任何影响。
答案 1 :(得分:0)
您已通过提供默认值使action
路由值可选。解析URL时会忽略可选值。
routes.MapRoute("ManageSpaces",
"ManageSpaces/{id}/{action}",
new { controller = "ManageSpaces", action = "overview"},
new { id = @"\d+" } //The regular expression \d+ matches one or more integers
);
如果您想在网址中加入action
,则必须将其设为必填参数。
routes.MapRoute("ManageSpaces",
"ManageSpaces/{id}/{action}",
new { controller = "ManageSpaces"},
new { id = @"\d+" } //The regular expression \d+ matches one or more integers
);