c# - Attribute routing and RouteLink -


i define home view

<body>     <div>          <h1>home</h1>         @html.routelink("r1", "first", new { user="r1"})         @html.routelink("r2", "second", new { company = "r2" })     </div> </body> 

and login controller

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 , r2 click routed correct action result index , index2 respectively .

but generate bellow error

the current request ambiguous between 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 happen.

instead of using {user} {company}, use user , company

example:

    [route("user", name = "first")]     public actionresult index(string user)     {         return view();     }     [route("company", name = "second")]     public actionresult index2(string company)     {         return view();     } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -