开发者

Pass an & as Part of a Route Parameter

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", "AffiliateEd开发者_Python百科it", 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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜