c# - Can i use RouteLink to change the parameter of the route depending on link clicked, MVC3 -


in global.asax.cs

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

i want parameter pagename "index" first home page loading. after on menu link click need transfer value of parameter pagename corresponding link , not value "index".hence wrote new maproute, pagename optional , not "index".

so in _layout.cshtml

foreach(...) {      @html.actionlink(item.title, "menu", "home", new { pagename = item.pagename, role = "admin" }, null)  } 

currently link click parameter value "index" taken, unintended. want 'index' 'home' or 'aboutus' or ''... depending on link user clicks.

after search, found routelink can change default route...

 @html.routelink(item.title, "newroute", new { pagename = item.pagename }) 

in effect, need specify defaultvalue pagename , should change on link clicks.

please tell me whether routelink solution issue.

in global.asax.cs, change {id} {pagename}

routes.maproute(         "default", // route name         "{controller}/{action}/{pagename}", // url parameters         new { controller = "home", action = "menu", pagename="index" } // parameter defaults     ); 

no need add new route , routelink not required. actionlink works.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -