I Define My
Home View like
<body>
<div>
<h1>Home</h1>
@Html.RouteLink("R1", "first", new { user="R1"})
@Html.RouteLink("R2", "second", new { company = "R2" })
</div>
</body>
and
login controller like
public class LoginController : Controller
{
// GET: Login
[Route("{user}", Name = "first")]
public ActionResult Index(string user)
{
return View();
}
[Route("{company}", Name = "second")]
public ActionResult Index2(string company)
{
return View();
}
}
RouteConfig
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
I imagine on home page
R1 and
R2 click its routed to correct action result Index and Index2 respectively .
But its generate bellow error
The current request is ambiguous between the following action methods:
System.Web.Mvc.ActionResult Index(System.String) on type MVCTest.Controllers.LoginController
System.Web.Mvc.ActionResult Index2(System.String) on type MVCTest.Controllers.LoginController
I have no Idea why this happen.