I have two routes declared in my route config like this:
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" }
);
I have two controller actions that look like this:
[HttpGet]
public ActionResult TheAction()
{
}
[HttpPost]
public ActionResult TheAction([ModelBinder(typeof(SpecificModelBinder))] SpecificModel model)
{
}
I want a link to the first of these actions in my view, so I generate one using Url.Action:
<a href="@Url.Action("TheAction", "Main")">The Action</a>
However, this outputs the url http://site/Main/TheAction/- (note the dash at the end, which seems to indicate that my SpecificAction route is being used.
Is there some way I can call Url.Action with a specific route? Or is there any other way I can avoid this dash appearing in the url?
Url.Actionrenders a URL... So your link is rendered as<a href="http://site/Main/TheAction/-">?<a href="@Url.Action("TheAction")">The Action</a>http://sitecoming from?