asp.net mvc从GET form post出站路由

asp.net mvc从GET form post出站路由,asp.net,asp.net-mvc-2,routing,Asp.net,Asp.net Mvc 2,Routing,我有一条路线如下所示: new { controller = "ControllerName", action = "PhotoGallery", slug = "photo-gallery", filtertype = UrlParameter.Optional, filtervalue = UrlParameter.Optional, sku = UrlParameter.Optional} <%using(Html.BeginForm("PhotoGallery", "Cont

我有一条路线如下所示:

new { controller = "ControllerName", action = "PhotoGallery", slug = "photo-gallery", filtertype = UrlParameter.Optional, filtervalue = UrlParameter.Optional, sku = UrlParameter.Optional}
  <%using(Html.BeginForm("PhotoGallery", "ControllerName", FormMethod.Get)) {%>
  <%:Html.Hidden("filtertype", "1")%>
  <%:Html.DropDownList("filtervalue", ViewData["Designers"] as SelectList, "Photos by designer", new { onchange = "selectJump(this)" })%>
  <%}%>
www.site.com/photo-gallery/1/selectedvalue
我有一张这样的表格:

new { controller = "ControllerName", action = "PhotoGallery", slug = "photo-gallery", filtertype = UrlParameter.Optional, filtervalue = UrlParameter.Optional, sku = UrlParameter.Optional}
  <%using(Html.BeginForm("PhotoGallery", "ControllerName", FormMethod.Get)) {%>
  <%:Html.Hidden("filtertype", "1")%>
  <%:Html.DropDownList("filtervalue", ViewData["Designers"] as SelectList, "Photos by designer", new { onchange = "selectJump(this)" })%>
  <%}%>
www.site.com/photo-gallery/1/selectedvalue
而不是像“


谢谢!

如果您只有一些参数,Mvc将创建一个查询字符串类型的Url,除非它找到一个完全匹配的Url

建议您将需要以下内容:

routes.Add("testRoute", 
new Route("/{action}/{controller}/{slug}/{filtertype}/{filtervalue}",
new { controller = "ControllerName", action = "PhotoGallery", slug = "photo-gallery", filtertype = UrlParameter.Optional, filtervalue = UrlParameter.Optional}
);

确保这是在您现有路线之前进行的

谢谢您的回复!我最终使用了PRG模式以获得所需的效果。我的路线太复杂了,不允许有这样的一般规则。