我创建了以下路由:
routes.MapRoute(
"TestRoute4", // Route name
"Report {ref_id} Test Board", // URL with parameters
new { controller = "stats", action = "index" } // Parameter defaults
);
public ActionResult index(string ref_id)
{
}这工作得很好,但我现在想让我的控制器知道它是从与Report 25 Test Board匹配的路由调用的。在MapRoute中,有没有一种方法可以让我也把其他东西传递给控制器?我甚至不介意硬编码。我只想通过报告和测试板这两个字。
希望你能帮上忙
曼迪
发布于 2011-03-24 21:45:03
使用DataTokens
Route route = routes.MapRoute(
"TestRoute4", // Route name
"Report {ref_id} Test Board", // URL with parameters
new { controller = "stats", action = "index" } // Parameter defaults
);
route.DataTokens["YourKey"] = "your value";在你的控制器上,你可以这样做:
public ActionResult Index() {
// check if matched route is TestRoute4 (optional)
if (this.RouteData.Route == RouteTable.Routes["TestRoute4"]) {
// do something
var val = this.RouteData.DataTokens["YourKey"];
}
}https://stackoverflow.com/questions/5420089
复制相似问题