我有控制器/动作:
public partial class MyControllerController : Controller {
public virtual ActionResult Index(string name, string category, DateTime? from = null, DateTime? to = null)
{
// ...
}
}
我希望我的 URL 看起来像这样:
/MyController/myname/mycategory
/MyController/myname/mycategory?from=10%2F01%2F2013%2000%3A00%3A00&to=10%2F31%2F2013%2023%3A59%3A59
我尝试过以下路线注册:
routes.MapRoute(
"MyRoutes",
"MyController/{name}/{category}/",
new
{
controller = "MyController",
action = "Index",
from = UrlParameter.Optional,
to = UrlParameter.Optional
});
它接受传入 URL,但在使用Url.Action()
方法时未生成正确的出站 URL。我Url.Action()
总是返回地址,例如:
/CouponManager?name=myname&category=mycategory&from=08%2F01%2F2013%2000%3A00%3A00&to=08%2F31%2F2013%2023%3A59%3A59
有人可以帮忙吗?