【发布时间】:2015-08-26 11:50:52
【问题描述】:
我正在关注这个帖子 RedirectToAction with parameter 来做这个
return RedirectToAction("index","service",new {groupid = service.GroupID});
由于某种原因,它返回的 URL 不是预期的。例如,它返回 http://localhost/appname/service?groupid=5,而不是 http://localhost/appname/service/index?groupid=5。有没有办法让它返回预期的 URL?
更新:RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
谢谢
【问题讨论】:
-
显示来自
RouteConfig.cs的路线 -
我无法重现您的问题(对我来说很好)。尽管我建议您将
ServiceController中的Index()方法的参数更改为int id而不是int groupid并使用return RedirectToAction("index","service",new {id = service.GroupID});,因此它会生成../Service/Index/5而不是../Service/Index?groupid=5(或使用` url: "服务/索引/{groupid}", -
@Ryios:GroupID 是整数类型。
-
@Stephen:将 groupid 更改为 id 后。有用。谢谢
标签: c# asp.net-mvc