Global.asax中路由值如何使用Html.ActionLink覆盖路由表的默认值?
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional, filterDate = DateTime.Now.AddDays(-1), filterLevel = "INFO" } // Parameter defaults
);
这里是我的ActionLink
@Html.ActionLink(item.MachineName, "Machine", new { id = item.MachineName, filterLevel = "hello" }, null)
当ActionLink的指定了filterlevel,它会产生这样的网址:
http://localhost:1781/LoggingDashboard/log/level/VERBOSE
是哪个与我目前相同的页面。如果我改变ActionLink的使用其他的属性不是一个有路由表(是的,如果我使用filterDate它也打乱了)的默认值,它会产生一个像这样的链接:
@Html.ActionLink(item.MachineName, "Machine", new { id = item.MachineName, foo = "bar" }, null)
http://localhost:1781/LoggingDashboard/log/Machine/C0UPSMON1?foo=bar
这是行为正确吗?我应该不能覆盖路由表中设置的默认值吗?我已经证实,如果我删除从路由表中的filterLevel默认情况下此工程,我想到:
http://localhost:1781/LoggingDashboard/log/Machine/C0UPSMON1?filterLevel=VERBOSE
---编辑--- 对不起,这里是行动
public ActionResult Machine(string id, DateTime filterDate, string filterLevel)
{
...
var model = new LogListViewModel { LogEntries = logEntries };
return View(model);
}
因为我想知道如何重写了在从Global.asax中的路由指定的“默认”值赏金。即我想能够覆盖filterLevel和filterDate。
什么是你的行动的签名看起来像? filterLevel是以字符串还是枚举类型的形式出现的? – StriplingWarrior 2011-02-01 17:17:28
我会在动作中定义这个,但是我想要一个像DateTime filterDate = DateTime.Now.AddDays(-1)这样的默认参数,它不能进入方法参数--FilterDate的默认参数值必须是编译时常量 – BlackICE 2011-02-01 17:34:25
你的路线是什么? – SLaks 2011-02-07 14:47:09