简体   繁体   English

区分大小写的GET

[英]Case Sensitive GET

I have an MVC application where I am passing some arguments via GET. 我有一个MVC应用程序,我通过GET传递了一些参数。 Everything works great but some of the information I am passing I would like to keep the case of. 一切都很好,但我想保留的一些信息正在传递。 For example one field I pass is title , so ?title=My Title that works great, except when I get to my controller method the value in the title field of my model is my title is there any way I can keep the case calling a controller in this manner? 例如,我传递的一个字段是title ,所以?title=My Title很好用,除非当我进入控制器方法时,模型标题字段中的值就是my title ,我可以通过任何方式保持大小写控制器以这种方式?

This is how I am calling the controller in javascript like so: 这就是我在javascript中这样调用控制器的方式:

var url = "@(Url.Content("~/Controller/Name/?title=My Title"))";

window.open(url, "_blank");

First make this function... 首先使这个功能...

function firstCharsToUpperCase( char ){
  return char[0].toUpperCase();
}

Then in your controller you should have access to params or a key/value pair of some sort like this... 然后在控制器中,您应该可以访问参数或类似这样的键/值对...

params['title'] = params['title'].replace(/\b[a-z]/ig, firstCharsToUpperCase);

You would then reassign the key title to the new value of "My Title" 然后,您需要将关键标题重新分配给“我的标题”的新值。

Also, params should be case insensitive. 同样,参数应该不区分大小写。 Perhaps there is something converting the URI? 也许有些东西可以转换URI?

Maybe its in the Url.content() function. 也许它在Url.content()函数中。 Can we see what it does? 我们能看到它做什么吗?

Also, here is an article regarding case sensitive routes Never Use Capital Letters 此外,这是有关区分大小写的路由的文章, 从不使用大写字母

UPDATE 更新

I found this 我找到了这个

If the specified content path does not start with the tilde (~) character, this method returns contentPath unchanged. 如果指定的内容路径不是以波浪号(〜)字符开头,则此方法将不变地返回contentPath。

here link 这里链接

Perhaps what it is saying is that if the '~' is left off, you will get what you give it. 也许这是在说,如果省略'〜',您将得到您所提供的。 Try it out and see? 试试看吧?

Case sensitive URLs are not a good idea even when not causing SEO issue, its just a bad idea. 即使不引起SEO问题,区分大小写的URL也不是一个好主意,这只是一个坏主意。 I developed a solution where I passed an ID in the URL and queried the necessary data from the DB within my controller. 我开发了一种解决方案,其中在URL中传递了ID,并从控制器中的数据库中查询了必要的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM