Man*_*eld 3 .net c# asp.net-mvc routes asp.net-mvc-4
我在路由配置中声明了两条路由,如下所示:
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" }
);
Run Code Online (Sandbox Code Playgroud)
我有两个控制器动作,如下所示:
[HttpGet]
public ActionResult TheAction()
{
}
[HttpPost]
public ActionResult TheAction([ModelBinder(typeof(SpecificModelBinder))] SpecificModel model)
{
}
Run Code Online (Sandbox Code Playgroud)
我希望在我的视图中链接到第一个这些操作,因此我使用Url.Action以下方法生成一个:
<a href="@Url.Action("TheAction", "Main")">The Action</a>
Run Code Online (Sandbox Code Playgroud)
但是,这会输出url http://site/Main/TheAction/-(注意末尾的破折号,这似乎表明我的SpecificAction路线正在使用中.
有什么方法可以Url.Action用特定路线打电话吗?或者有没有其他方法可以避免在网址中出现这个短划线?
| 归档时间: |
|
| 查看次数: |
8085 次 |
| 最近记录: |