特定的路線我在我的路線配置聲明如下兩種途徑:使用與Url.Action
routes.MapRoute(
name: "SpecificAction",
url: "{controller}/{action}/{id}-{id2}",
defaults: new { controller = "Main", action = "SpecificAction", id = UrlParameter.Optional, id2 = UrlParameter.Optional }
);
routes.MapRoute(
name: "DefaultNoParams",
url: "{controller}/{action}/",
defaults: new { controller = "Main", Action = "Index" },
namespaces: new string[1] { "Project.Controllers" }
);
我有一個看起來像這兩控制器操作:
[HttpGet]
public ActionResult TheAction()
{
}
[HttpPost]
public ActionResult TheAction([ModelBinder(typeof(SpecificModelBinder))] SpecificModel model)
{
}
我想鏈接到第一,我認爲這些行動,所以我生成一個使用Url.Action
:
<a href="@Url.Action("TheAction", "Main")">The Action</a>
然而,這輸出url http://site/Main/TheAction/-
(注意最後一個破折號,這似乎表明我的SpecificAction
路由正在使用。
有一些方法我可以調用Url.Action
與特定的路線?或者有沒有其他的方法可以避免這種短跑出現在網址中?
路由表不會影響Url.Action呈現URL的方式......所以你的鏈接呈現爲''? –
@ChrisHardie Yes, I just want to avoid that. – Mansfield
Odd... What is rendered when you add this to your View: 'The Action' –