我有这样路由可选布尔值
public ActionResult DoSomething(bool special = false)
{
// process the special value in some special way...
return View();
}
我要访问使用仅由特殊的标记不同的两种不同的链接此操作的MVC控制器操作方法,我想通过标志作为一个人类可读的路线价值。 更确切地说,这些链接应该是这样的:
SomeController/DoSomething
SomeController/DoSomething/Special
目前我已经创建动作链接:
@Html.ActionLink("Just do it", "DoSomething", "SomeController")
@Html.ActionLink("Do it in a special way", "DoSomething", "SomeController", new { special = true}, null)
这个代码生成像这样的链接:
SomeController/DoSomething/Special
SomeController/DoSomething?special=True
显然,我需要一个特殊的路线,第二个链接变成SomeController/DoSomething/Special
但我所有的尝试都失败了,因为在一次MapRoute尝试中,它忽略了我的特殊fl ag,在另一个MapRoute尝试它使两个链接都变为SomeController/DoSomething/Special
,尽管我没有为第一个ActionLink指定特殊路由值(我猜它只是从路由中选取它)。
将bool special
映射到URL SomeController/DoSomething/Special
并使ActionLink生成正确链接的正确方法是什么?