Reputation: 112
I am using asp.net MVC 3.0. I want Passing parameter with URL. It works. But if my parameter value is like shahin & karina. Then it count as a two value beacuse of &. I want to inculed & as a vlue. How can I do that. Please, Anyone has solved this kind of problem.
For example: My controller function is:
public ActionResult Index(string name)
{}
html code
<a href="/stat?name=shahin & karina">
Form the controller I got only name value is: shahin But I need Name value is: shahin & karina
Thanks advance..
Upvotes: 3
Views: 773
Reputation: 83
You have to encode '&' as an HTML entity.
<a href="/stat?name=shahin%20%26%20karina" />
Upvotes: 1
Reputation: 41560
Try rewriting the html code as:
<a href="/stat?shahin%20%26%20karina" />
%20
is a url-encoded space and %26
is the url-encoded ampersand
You can use this tool to try encoding different strings (in this example, you would encode "shahin & karina")
Upvotes: 0
Reputation: 71
You need to encode the URL. There is surely a library for it in .NET.
Similar tools: http://meyerweb.com/eric/tools/dencoder/
Cheers HH
Upvotes: 1
Reputation: 48006
I believe all you would need to do is URL encode the ampersand (and possibly the space character).
Try something like this -
<a href="/stat?name=shahin%20%26%20karina">
%20
is an encoded space character.%26
- is the encoded ampersand character.I have absolutely zero knowledge or experience with asp.net
but I'm fairly sure that there are native URL encoding functions...
Upvotes: 1