这是我的mvc3应用程序的路由配置
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 }
);
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,这是mvc3应用程序的默认路由,您可以注意到我根本没有更改它.所以当我试图RouteUrl像这样使用url helper时
@Url.RouteUrl("Default",
new { Action = "RegistrarPago",
IDPago = ViewBag.IDPago,
confirmNumber = ViewBag.ConfirmationNumber },
Request.Url.Scheme)
Run Code Online (Sandbox Code Playgroud)
输出就是这个
http://localhost/DescuentoDemo/pago/RegistrarPago?IDPago=60&confirmNumber=1798330254
这个url基本上对于这个字符amp;是错误的帮助器有什么问题我假设这是一个编码问题,但为什么呢?
该@剃须刀功能默认不HTML编码.Url.RouteUrl帮助者没有任何问题.这是你正在使用它的上下文.
就好像你在Razor视图中写下了以下内容:
@("http://localhost/DescuentoDemo/pago/RegistrarPago?IDPago=60&confirmNumber=1798330254")
Run Code Online (Sandbox Code Playgroud)
您正在HTML页面上输出它的结果,所以正确的做法是对HTML进行编码.如果您不想进行HTML编码,请使用以下Html.Raw函数:
@Html.Raw(Url.RouteUrl("Default",
new { Action = "RegistrarPago",
IDPago = ViewBag.IDPago,
confirmNumber = ViewBag.ConfirmationNumber },
Request.Url.Scheme))
Run Code Online (Sandbox Code Playgroud)
如果你想生成一个指向这个url的锚,你可以Html.RouteLink在这种情况下直接使用帮助器.
| 归档时间: |
|
| 查看次数: |
1352 次 |
| 最近记录: |