c# - Url parameter not mapping -


i have following method in blogcontroller:

[httpget] [route("blog/search/{searchtag:string}")] public actionresult search(string searchtag) {     // doing search } 

i want url example blog/search/programming , should me page showing posts tagged programming

i have following route:

routes.maproute(     name: "blogsearchroute",     url: "{controller}/{action}/{searchtag}",     defaults: new {           controller = "blog",           action = "search"      } ); 

unfortunately parameter doesn't map correctly , null.

update
additional information: here routeconfig class:

public class routeconfig     {         public static void registerroutes(routecollection routes) {             routes.lowercaseurls = true;             routes.ignoreroute("{resource}.axd/{*pathinfo}");             routes.ignoreroute("elmah.axd");                            routes.maproute(                 name: "blogsearchroute",                 url: "{controller}/{action}/{searchtag}",                 defaults: new { controller = "blog", action = "search", searchtag = urlparameter.optional });              routes.maproute(                 name: "blogroute",                 url: "{controller}/{action}/{id}/{title}",                 defaults: new { controller = "blog", action = "post", title = urlparameter.optional});              routes.maproute(                 name: "default",                 url: "{controller}/{action}/{id}",                 defaults: new { controller = "home", action = "index", id = urlparameter.optional }             );         }     } 

in custom route, define searchtag optional using:

routes.maproute(     name: "blogsearchroute",     url: "{controller}/{action}/{searchtag}",     defaults: new {           controller = "blog",           action = "search",          searchtag = urlparameter.optional     } ); 

update

you should define default route @ bottom under custom routes.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -