Reputation: 1447
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");
Upvotes: 0
Views: 141
Reputation: 1447
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.
Upvotes: 0
Reputation: 15922
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?
Upvotes: 1