asp.net-mvc – ASP.NET MVC – 将多个查询字符串参数映射到一个漂亮的URL

栏目: ASP.NET · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/417000/asp-net-mvc-mapping-more-than-one-query-string-parameter-to-a-pretty-url

我对mvc的seo友好网址的设计有点困惑….以下面的网址为例:

http://myapp/venues/resturants.aspx?location=central&orderBy=top-rated

使用我的mvc应用程序,我已将其映射如下:

http://myapp/venues/list/resturants/central/top-rated

{控制器} / {行动} / {类别} / {位置} / {顺序}

现在唯一的问题是位置和顺序是可选的…因此应该可以提交如下的请求: http://myapp/venues/list/resturants/top-rated .当请求到达控制器动作时,这证明是一个问题,位置参数自然地获得了“最高评级”.

有什么建议?我正在考虑使用显式查询字符串来处理多个参数,但这实际上是我的最后一个选项,因为我不想太多地牺牲SEO.

有没有人遇到过这种困境?你是怎么处理的?

提前致谢!

假设位置和顺序的允许值是唯一的(即当它们进入时,你可以将它们分开,或者如果它们只提供一个,你怎么知道它是一个位置还是一个订单?),那么你可以只取两个参数并计算出它们在控制器中的含量.

路线:{controller} / {action} / {param1} / {param2}

控制器动作:

public ActionResult MyAction(string param1, string param2)
{
    string location;
    string order;
    if (!ParseLocation(param1, out location))
    { ParseLocation(param2, out location); }
    // ...
}

不是特别优雅,但可以让你拥有你想要的URL.

翻译自:https://stackoverflow.com/questions/417000/asp-net-mvc-mapping-more-than-one-query-string-parameter-to-a-pretty-url


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Computers and Intractability

Computers and Intractability

M R Garey、D S Johnson / W. H. Freeman / 1979-4-26 / GBP 53.99

This book's introduction features a humorous story of a man with a line of people behind him, who explains to his boss, "I can't find an efficient algorithm, but neither can all these famous people." ......一起来看看 《Computers and Intractability》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具