我的路由配置中声明了两个路由,如下所示:
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中出现这个破折号?
Url.Action
如何呈现URL...因此您的链接将呈现为<a href="http://site/Main/TheAction/-">
? - Mister Epic<a href="@Url.Action("TheAction")">The Action</a>
。 - Mister Epichttp://site
是从哪里来的? - Mister Epic