表单发布到错误的 URL
原标题: 无法修复配置错误的路线
我想根据过滤器(有 4 个可能的值)和用户输入的条件进行搜索。
我有以下路线:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"SubLineasProductosDefault",
"SubLineasProductos.aspx/Create",
new { controller = "SubLineasProductos", action = "Create" }
);
routes.MapRoute(
"SubLineasProductosSearch",
"SubLineasProductos/Buscar.aspx/{filtro}/{criterio}",
new { controller = "SubLineasProductos", action = "Buscar"}
);
routes.MapRoute(
"SubLineasProductos",
"SubLineasProductos.aspx/{id}",
new { controller = "SubLineasProductos", action = "Index", id = "" }
);
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
routes.MapRoute("Root", "", new { controller = "Home", action = "Index",
id = "" });
和以下表单:
<% using (Html.BeginForm("Buscar", "SubLineasProductos",
FormMethod.Get)) { %>
<%= Html.Hidden("filtro", "nombre") %>
<%= Html.TextBox("criterio") %>
<button type="submit" title="Buscar">
<img src='<%= Url.Content("") %>' alt="" />
</button>
<% } %>
该表单不会重定向到操作 Buscar,而是重定向到 SubLineasProductos 控制器中的操作 Index。 我认为我的路线错误,但我不知道如何修复它们。 我已阅读这篇文章,据我所知,我的路线一切正常。
我怎样才能解决这个问题? 提前致谢。
编辑:使用 Phil 提供的工具,我可以看到,如果我测试像这样的 URL
http://localhost/MyApp/SubLineasProductos/Buscar.aspx/nombre/block
符合我想要的路线。 但是,当我运行我的应用程序并尝试使用在生成的 URL 具有以下形式之前发布的表单时:
http://localhost/MyApp/SubLineasProductos.aspx/Buscar ?filtro=nombre&criterio=块
我该如何解决这个新问题?
Original title: Can't fixed misconfigured routes
I want to make a search based in a filter (with 4 possibles values) and a criteria entered by the user.
I have the following routes:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"SubLineasProductosDefault",
"SubLineasProductos.aspx/Create",
new { controller = "SubLineasProductos", action = "Create" }
);
routes.MapRoute(
"SubLineasProductosSearch",
"SubLineasProductos/Buscar.aspx/{filtro}/{criterio}",
new { controller = "SubLineasProductos", action = "Buscar"}
);
routes.MapRoute(
"SubLineasProductos",
"SubLineasProductos.aspx/{id}",
new { controller = "SubLineasProductos", action = "Index", id = "" }
);
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
routes.MapRoute("Root", "", new { controller = "Home", action = "Index",
id = "" });
and the following form:
<% using (Html.BeginForm("Buscar", "SubLineasProductos",
FormMethod.Get)) { %>
<%= Html.Hidden("filtro", "nombre") %>
<%= Html.TextBox("criterio") %>
<button type="submit" title="Buscar">
<img src='<%= Url.Content("") %>' alt="" />
</button>
<% } %>
The form isn't redirecting to the action Buscar, but to the action Index in the SubLineasProductos controller. I think I have wrong my routes, but I don't know how to fixed them. I have read this post, and as much I can see all is fine in my routes.
How can I fix this? Thanks in advance.
EDIT: With the tool provided by Phil I can see that if I test an URL like
http://localhost/MyApp/SubLineasProductos/Buscar.aspx/nombre/block
it matches the route I want. But when I run my application and try to use the form posted before the generated URL has the form:
http://localhost/MyApp/SubLineasProductos.aspx/Buscar?filtro=nombre&criterio=block
How can I fix this new problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用我在此处发布的路由调试器: http:// /haacked.com/archive/2008/03/13/url-routing-debugger.aspx
Have you tried using the Route Debugger I posted here: http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx