c# - Can't bind to parameter -


i've got default routing:

routes.maproute(             "shortie", // route name             "{controller}/{id}", // url parameters             new { controller = "ettan", action = "index", id = "id" } // parameter defaults             );  routes.maproute(             "default", // route name             "{controller}/{action}/{id}", // url parameters             new { controller = "ettan", action = "index", id = urlparameter.optional } // parameter defaults             ); 

i've got controller: newscontroller. has 1 method, this:

public actionresult index(int id) {   ... } 

if browse /news/index/123, works. /news/123 works. however, /news/index?id=123 not (it can't find method named "index" id allowed null). seem lacking understanding on how routing , modelbinder works together.

the reason asking want have dropdown different news sources, parameter "id". can select 1 news source (for instance "sport", id = 123) , should routed index method. can't seem work.

the asp.net mvc routing works using reflection. inside controller method matching pattern defining in routes. if can't find one...well you've seen happens.

so answer (as posted in comments) change type of id parameter nullable<int> i.e. int?.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -