Boris Callens
Boris Callens

Reputation: 93337

Pass URL as get parameter?

I'm trying to pass u url as parameter to a get method. I defined a route that accepts a {*url} parameter so I can send "/" characters without it separating my parameter. As soon as there is a ":" in the url (like in http: or localhost:3857 for example), the method never gets hit.

The Html.ActionLink method escapes it's parameter itself, but it doesn't seem to escape the ':'. I cannot escape it manually because then the escape characters get escaped by the very same Html.Actionlink method.

any ideas?

Upvotes: 6

Views: 8229

Answers (3)

tessa
tessa

Reputation: 828

I ran into the same problem. I ended up removing the Html.ActionLink and replaced it with:

<a href="[email protected]">@item.Title</a>

@item.ID is a url returned from the netflix api, example http://api.netflix.com/catalog/titles/series/70021357/seasons/70021357. Now my url looks like this - /Home/Movies?id=http://api.netflix.com/catalog/titles/series/70021357/seasons/70021357, and I just used Request.QueryString to get the value in the controller:

Request.QueryString.Get("id")

Probably not ideal but it works for now.

Upvotes: 1

Piskvor left the building
Piskvor left the building

Reputation: 92772

It's a bit of a hack, but you could replace the ':' with '%3A' (which is the escaped form), and see what the ActionLink does with it. If it's escaped once more, you'd have to replace the twice-escaped version back to ':' at the server, otherwise just replace '%3A' back to ':'

Upvotes: 0

Kieveli
Kieveli

Reputation: 11075

Use EncodeUrl before you pass it, and then decode it on the other side.

Upvotes: 3

Related Questions