表单发布到错误的 URL

发布于 2024-07-28 23:22:54 字数 2357 浏览 6 评论 0原文

原标题: 无法修复配置错误的路线

我想根据过滤器(有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦罢 2024-08-04 23:22:54

您是否尝试过使用我在此处发布的路由调试器: 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文