简体   繁体   中英

Case Sensitive GET

I have an MVC application where I am passing some arguments via 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?

This is how I am calling the controller in javascript like so:

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?

Maybe its in the Url.content() function. 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.

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. I developed a solution where I passed an ID in the URL and queried the necessary data from the DB within my controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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