c# - 2 optional integer parameters -


my user controller action looks like:

[httpget] public actionresult choose(int? userid, int? locationid) {  } 

the url like:

/user/choose 

or

/users/user/choose/{userid}/{locationid} 

i tried add area routes:

context.maproute(     "user_choose",     "users/{controller}/{action}/{userid}/{locationid}",         new { controller = "reward", action = "choose", userid = urlparameter.optional } ); 

now if go url like:

/users/user/choose/123/456 

i see userid parameter has value, locationid null.

what issue be?

the fix might lie here:

context.maproute(     "user_choose",     "users/{controller}/{action}/{userid}/{locationid}",         new { controller = "reward", action = "choose", userid = urlparameter.optional, locationid = urlparameter.optional} ); 

you must specify brackets mean anonymous object i.e. set default values.

edit: there no problem in code. controller:

namespace webapplication3.areas.users.controllers {     public class usercontroller : controller     {         // get: users/user         public actionresult index()         {             return view();         }         [httpget]         public actionresult choose(int? userid, int? locationid)         {             return view();         }     } } 

usersarearegistration.cs:

namespace webapplication3.areas.users {     public class usersarearegistration : arearegistration      {         public override string areaname          {                          {                 return "users";             }         }          public override void registerarea(arearegistrationcontext context)          {             context.maproute(                 "user_choose",                 "users/{controller}/{action}/{userid}/{locationid}",                     new { controller = "reward", action = "choose", userid = urlparameter.optional }             );         }     } } 

global.asax:

namespace webapplication3 {     public class mvcapplication : system.web.httpapplication     {         protected void application_start()         {             arearegistration.registerallareas();             filterconfig.registerglobalfilters(globalfilters.filters);             routeconfig.registerroutes(routetable.routes);             bundleconfig.registerbundles(bundletable.bundles);         }     } } 

and both values url provided in chose() method. actual problem might lie in namespaces.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -