RAZOR视图中Get方法的友好URL

时间:2022-02-08 15:12:02

Hi i have a page in razor that sorts an information, every time i need to make some change to my search i have to pass values by QueryString, i have many reasons to do that.

嗨我有一个剃刀页面对信息进行排序,每次我需要对我的搜索进行一些更改我必须通过QueryString传递值,我有很多理由这样做。

now my url looks like this:

现在我的网址看起来像这样:

https://localhost:44300/Reports/TitleSearch/SearchDirectTarade/DirectTradeExclusive?Input.SelectedMarket=DirectTradeExclusive&Input.SelectedProduct=131&Input.SelectedIssuer=&Input.SelectedOperation=C&Input.SelectedSubjacentGroup=&Input.SelectedSubjacent=US0028962076&Input.SelectedStrike=#

and i want to make it look like this:

我想让它看起来像这样:

https://localhost:44300/Reports/TitleSearch/SearchDirectTarade/DirectTradeExclusive

i also need to pass all those parameters by query string, so there is any possibility to make my URL more user friendly in MVC4 Razor pages?

我还需要通过查询字符串传递所有这些参数,所以有可能使我的URL在MVC4 Razor页面中更加用户友好吗?

4 个解决方案

#1


0  

@Url.Action('MyAction', 'MyController', 
    new { Input.SelectedMarket = DirectTradeExclusive, 
          Input.SelectedProduct = 13 } )

#2


0  

If, like you said, "every time i need to make some change to my search i have to pass values by QueryString" then you have no other option but to pass them in the QueryString.

如果像你说的那样,“每次我需要对我的搜索进行一些更改时,我必须通过QueryString传递值”,那么除了在QueryString中传递它们之外别无选择。

If you did not want to have the parameters in the URL, you could use a POST when you change the search or you could also set them in a cookie or session.

如果您不想在URL中包含参数,则可以在更改搜索时使用POST,也可以在cookie或会话中设置它们。

#3


0  

The main question here is why do you want to make this url user friendly?
If your main goal is to allow user to send/store this link to similate same request later, then you are already solved your problem. In other case, if you, for instanse, want to let user to remember short url, then you have to either reduce the number of search parameters, or hash your search url (like bit.ly does).
Basically, I can think about a few solutions:
if you don't need repetative searches by url:

这里的主要问题是为什么你想让这个网址用户友好?如果您的主要目标是允许用户稍后发送/存储此链接以模拟相同的请求,那么您已经解决了您的问题。在其他情况下,如果您(对于instanse)想要让用户记住短网址,那么您必须减少搜索参数的数量,或者对搜索网址进行哈希处理(如bit.ly所做)。基本上,我可以考虑一些解决方案:如果您不需要通过url进行重复搜索:

  • hide query parameters in POSTed values
  • 在POSTed值中隐藏查询参数

  • hide query parameters in cookies or httpheaders (be careful, some firewals filters unknown headers)
  • 隐藏cookie或httpheaders中的查询参数(小心,一些firewals过滤未知标题)

if you want search to be repetative:

如果你想搜索重复:

  • move query parameters to url path (you may mark them as optional in routing)
  • 将查询参数移动到url路径(您可以在路由中将它们标记为可选)

  • (My favourite) Leave as is, or maybe just to shorten query parameters' names
  • (我最喜欢的)保持原样,或者只是缩短查询参数的名称

Basically, if you don't have limited number of searched options and don't have to have landing pages for them (screw you SEO), it's a common practive to GET your search results and put search parameters in query string (Google is a most notable example)

基本上,如果你没有有限数量的搜索选项而且没有必要的登陆页面(搞砸了你的搜索引擎优化),那么获取搜索结果并将搜索参数放入查询字符串(谷歌是一个最值得注意的例子)

#4


0  

you can change URL logic or patteren & defaults values in App_Start/Route_Config file

您可以在App_Start / Route_Config文件中更改URL逻辑或patteren和默认值

Default patteren could be changed.

默认模式可以更改。

#1


0  

@Url.Action('MyAction', 'MyController', 
    new { Input.SelectedMarket = DirectTradeExclusive, 
          Input.SelectedProduct = 13 } )

#2


0  

If, like you said, "every time i need to make some change to my search i have to pass values by QueryString" then you have no other option but to pass them in the QueryString.

如果像你说的那样,“每次我需要对我的搜索进行一些更改时,我必须通过QueryString传递值”,那么除了在QueryString中传递它们之外别无选择。

If you did not want to have the parameters in the URL, you could use a POST when you change the search or you could also set them in a cookie or session.

如果您不想在URL中包含参数,则可以在更改搜索时使用POST,也可以在cookie或会话中设置它们。

#3


0  

The main question here is why do you want to make this url user friendly?
If your main goal is to allow user to send/store this link to similate same request later, then you are already solved your problem. In other case, if you, for instanse, want to let user to remember short url, then you have to either reduce the number of search parameters, or hash your search url (like bit.ly does).
Basically, I can think about a few solutions:
if you don't need repetative searches by url:

这里的主要问题是为什么你想让这个网址用户友好?如果您的主要目标是允许用户稍后发送/存储此链接以模拟相同的请求,那么您已经解决了您的问题。在其他情况下,如果您(对于instanse)想要让用户记住短网址,那么您必须减少搜索参数的数量,或者对搜索网址进行哈希处理(如bit.ly所做)。基本上,我可以考虑一些解决方案:如果您不需要通过url进行重复搜索:

  • hide query parameters in POSTed values
  • 在POSTed值中隐藏查询参数

  • hide query parameters in cookies or httpheaders (be careful, some firewals filters unknown headers)
  • 隐藏cookie或httpheaders中的查询参数(小心,一些firewals过滤未知标题)

if you want search to be repetative:

如果你想搜索重复:

  • move query parameters to url path (you may mark them as optional in routing)
  • 将查询参数移动到url路径(您可以在路由中将它们标记为可选)

  • (My favourite) Leave as is, or maybe just to shorten query parameters' names
  • (我最喜欢的)保持原样,或者只是缩短查询参数的名称

Basically, if you don't have limited number of searched options and don't have to have landing pages for them (screw you SEO), it's a common practive to GET your search results and put search parameters in query string (Google is a most notable example)

基本上,如果你没有有限数量的搜索选项而且没有必要的登陆页面(搞砸了你的搜索引擎优化),那么获取搜索结果并将搜索参数放入查询字符串(谷歌是一个最值得注意的例子)

#4


0  

you can change URL logic or patteren & defaults values in App_Start/Route_Config file

您可以在App_Start / Route_Config文件中更改URL逻辑或patteren和默认值

Default patteren could be changed.

默认模式可以更改。