Possible Duplicate:
How does StackOverflow generate its SEO-friendly URLs?
I made a simple form that contains the NAME and some other fields.
When user submits form, the following route will be called: ~/Profile/NAMEIf user entered John Smith as NAME, my URL will be:
~/Profile/John%Smith And I want it to be: ~/Profile/John-SmithThe application will display user details and again the same form at the top of the page.
NAME value will be passed to the form via ViewData. I want to populate text box with John Smith, not John-Smith.How can I do that? I 开发者_如何学编程ran out of ideas.
Thanks in advance!EDIT:
I have found solution here: http://goneale.com/2008/12/19/lowercase-route-urls-in-aspnet-mvc/.
It needs a little modification, but basically this is it.HttpUtility, look into UrlDecode / UrlEncode
Edit
Use jQuery. Pseudo:
<input type="text" value="name" />
<input type="submit" id="submit" />
The jQuery
$('submit').click(function() {
$('name').val($('name').val().replace(' ', '-'));
});
It can look something like that, and when you want to display it, you just replace - with space, but remember, there are names that contain - and should not be replaced.
If it helps any, I used this from Jeff Atwood as well as the link you garnered above to make it happen.
精彩评论