Parameter value not passed in ASP.NET MVC route -


i'm learning creating custom routes in asp.net mvc , have hit brick wall. in global.asax.cs file, i've added following:

public static void registerroutes(routecollection routes) {     routes.ignoreroute("{resource}.axd/{*pathinfo}");      routes.maproute(         "default", // route name         "{controller}/{action}/{id}", // url parameters         new { controller = "home", action = "index", id = urlparameter.optional } // parameter defaults     );      // custom route.     routes.maproute(         "user_filter",         "home/filter/{name}",         new { controller = "home", action = "filter", name = string.empty }     ); } 

the idea me able navigate http://localhost:123/home/filter/mynameparam. here controller:

public class homecontroller : controller {     public actionresult index()     {         return view();     }      public actionresult filter(string name)     {         return this.content(string.format("you found me {0}", name));     } } 

when navigate http://localhost:123/home/filter/mynameparam contoller method filter called, parameter name null.

could give pointer correct way me build custom route, passes name part in url name parameter filter().

the default route should last one. try way:

public static void registerroutes(routecollection routes) {     routes.ignoreroute("{resource}.axd/{*pathinfo}");      // custom route.     routes.maproute(         "user_filter",         "home/filter/{name}",         new { controller = "home", action = "filter", name = string.empty }     );      routes.maproute(         "default", // route name         "{controller}/{action}/{id}", // url parameters         new { controller = "home", action = "index", id = urlparameter.optional } // parameter defaults     ); } 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -