Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Define My Home View like

HTML
<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

SQL
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
C#
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
C#
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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900