如何使ASP.NET路由退路值? [英] How to make ASP.NET Routing escape route values?

查看:132
本文介绍了如何使ASP.NET路由退路值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要像 / {控制器} / {ID} / {行动} / {日期} ,其中日期路线一个ASP.NET MVC网站是的 MM / DD / YYYY 的的日期/时间部分。 (我处理时间维的数据,所以我需要一个既ID和时间做大多数操作点)

I have an ASP.NET MVC site where I want routes like /{controller}/{id}/{action}/{date}, where "date" is the mm/dd/yyyy portion of a date/time. (I'm dealing with time-dimensioned data, so I need both an ID and a point in time to do most operations)

这个路线很简单:

routes.MapRoute(
    "TimeDimensionedRoute",
    "{controller}/{id}/{action}/{date}",
    new { controller = "Iteration", action = "Index", id = String.Empty, date = String.Empty }
);

这条路线正确映射 /美孚/ 100 /编辑/ 01%2F21%2F2010 到所需的操作。 更新:这是不正确。这是不正确的路由,我错了。请参阅接受的答案链接的相关问题。

我的问题是,当我使用Html.ActionLink()来生成一个链接,这条路线,它的不URL-CN code日期并我结束了这种无效的网址为 /美孚/ 100 /编辑/ 01 /二千〇一十分之二十一

My problem is that when I use Html.ActionLink() to generate a link for this route, it does not URL-encode the date and I end up with invalid URLs such as "/Foo/100/Edit/01/21/2010".

有没有什么办法让c代表我的价值观路由基础设施的连接$ C $?这似乎是错误的,我必须手动URL-CN $,我传递给HTML佣工C $ C数据。

Is there any way to get the routing infrastructure to encode the values for me? It seems wrong that I have to manually URL-encode data that I pass to the HTML helpers.

推荐答案

您不能在ASP.NET MVC路由值中使用斜杠。即使是URL恩codeD它不会工作。

You can not use a forward slash in a route value in ASP.NET MVC. Even if it is URL-encoded it wont work.

在网址削减

有只有一个解决方案,如果您使用ASP.NET 4.0

There is only a solution if you use ASP.NET 4.0

这篇关于如何使ASP.NET路由退路值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆