Built in method to encode ampersands in urls returned from Url.Action?

Posted by Blegger on Stack Overflow See other posts from Stack Overflow or by Blegger
Published on 2010-05-24T17:20:44Z Indexed on 2010/05/25 2:41 UTC
Read the original article Hit count: 412

I am using Url.Action to generate a URL with two query parameters on a site that has a doctype of XHTML strict.

Url.Action("ActionName", "ControllerName", new { paramA="1" paramB="2" })

generates:

/ControllerName/ActionName/?paramA=1&paramB=2

but I need it to generate the url with the ampersand escaped:

/ControllerName/ActionName/?paramA=1&paramB=2

The fact that Url.Action is returning the URL with the ampersand not escaped breaks my HTML validation. My current solution is to just manually replace ampersand in the URL returned from Url.Action with an escaped ampersand. Is there a built in or better solution to this problem?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-2