Reputation: 18237
This is my routing configuration of my mvc3 application
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
// Parameter defaults:
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
As you can see this is the default routing of a mvc3 application and you can notice that I don't change it at all. So when I was tried to use the url helper RouteUrl
like this
@Url.RouteUrl("Default",
new { Action = "RegistrarPago",
IDPago = ViewBag.IDPago,
confirmNumber = ViewBag.ConfirmationNumber },
Request.Url.Scheme)
The output is this
http://localhost/DescuentoDemo/pago/RegistrarPago?IDPago=60&confirmNumber=1798330254
This url it's wrong basically for this characters amp;
What's wrong with the helper I'm assuming that's a encoding problem but why?
Upvotes: 3
Views: 1558
Reputation: 1038720
The @
Razor function does HTML encoding by default. There's nothing wrong with the Url.RouteUrl
helper. It's the context you are using it in.
It' as if you wrote the following in a Razor view:
@("http://localhost/DescuentoDemo/pago/RegistrarPago?IDPago=60&confirmNumber=1798330254")
You are outputting the result of it on an HTML page, so the correct thing to do is to HTML encode it. If you don't want to HTML encode then use the Html.Raw
function:
@Html.Raw(Url.RouteUrl("Default",
new { Action = "RegistrarPago",
IDPago = ViewBag.IDPago,
confirmNumber = ViewBag.ConfirmationNumber },
Request.Url.Scheme))
And if you want to generate for example an anchor pointing to this url you directly use the Html.RouteLink
helper in this case.
Upvotes: 9