我不是在用GET方法的表单越来越友好的URL [英] I'm not getting friendly url in a form with GET method
问题描述
我设置这样的路线:
routes.MapRoute(
名称:Pesquisar
网址:Pesquisar / AAA {} / {} BBB /(编号),
默认:新{控制器=家,行动=Pesquisar
AAA = UrlParameter.Optional,
BBB = UrlParameter.Optional,
ID = UrlParameter.Optional
}
);
当我preSS的形式发送按钮(GET方法)的URL是这样的:
的http://本地主机:00000 / Pesquisar AAA =的One&安培; BBB =两个
但我期待的:
的http://本地主机:00000 / Pesquisar /单/双
当我preSS的形式发送按钮(GET方法)的URL是这样的:
http://mydomain.com/Pesquisar?aaa=One&bbb=Two
块引用>但我期待的:
块引用>这是因为在浏览器不知道你想要的花式URL,因为标准形式
获取
的方法是的追加形式在查询字符串值的你所最有可能需要做的就是类似<一个href=\"http://stackoverflow.com/questions/7799975/creating-canonical-urls-including-an-id-and-title-slug\">Creating规范的URL包括一个ID和标题塞,除了重定向到你想要的网址,如果它不是你要显示的URL。
或者你也可以使用jQuery手动创建你想在提交的URL,但是需要更多的客户端的工作。
I setup a route like that:
routes.MapRoute( name: "Pesquisar", url: "Pesquisar/{aaa}/{bbb}/{id}", defaults: new { controller = "Home", action = "Pesquisar", aaa = UrlParameter.Optional, bbb = UrlParameter.Optional, id = UrlParameter.Optional } );
When I press Send button in a form (with GET method) the url is like that:
http://localhost:00000/Pesquisar?aaa=One&bbb=Two
But I was expecting for:
http://localhost:00000/Pesquisar/One/Two
解决方案When I press Send button in a form (with GET method) the url is like that:
But I was expecting for:
This is because the browser is unaware of the fancy url you want, as the standard form
Get
method is to append form values in the querystring.What you mostly likely have to do is something like Creating Canonical URLs including an id and title slug, except redirect to the url you want if it's not the url you want to display.
Or you can use jQuery to manually create the url you want on submit, but requires more client side work.
这篇关于我不是在用GET方法的表单越来越友好的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!