views:

17

answers:

1

Unfortunately I need to accept a route parameter with an & in it. I have this route definition. The id parameter will sometimes have an & in it like this X&Y001.

        routes.MapRoute(
            "AffiliateEdit",
            "Admin/EditAffiliate/{*id}",
            new { controller = "UserAdministration", action = "EditAffiliate", id = ""}
        );

I have tried working around this issue in the following ways however none of them have worked. All of these result in an HTTP 400 Bad Request error in the browser.

<a href="/Admin/EditAffiliate/<%= a.CustomerID.Replace("&", "%26") %>">Edit</a>

This gives me <a href="/Admin/EditAffiliate/X%26Y001">Edit</a>

<%= Html.RouteLink("Edit", "AffiliateEdit", new { id = a.CustomerID }) %>

This gives me <a href="/Admin/EditAffiliate/X&amp;Y001">Edit</a>

<%= Html.RouteLink("Edit", "AffiliateEdit", new { id = Url.Encode(a.CustomerID) }) %>

This gives me <a href="/Admin/EditAffiliate/X%2526Y001">Edit</a>

A: 

the only thing I can think of (which is a "dirty" solution) is to encode the & yourself. for example something like ##26##. make sure to check the decoding algorithm only decodes the & ids and not some id that happens to contain ##26## for example.

A better solution depending on db size is to change the offending ids in the database.

Circadian
Thanks. It's an ugly fix but it works.
MHinton