c# - MVC 2 routes appearing as parameters -


i trying build route format of {controller}{action}{classificationid}{reviewid}{categoryid}\

but want able address without final categoryid , have default 1 isn't given.

here routes:

        routes.maproute(             "default", // route name             "{controller}/{action}/{id}", // url parameters             new { controller = "home", action = "index", id = urlparameter.optional } // parameter defaults         );          routes.maproute(             "schoolroutenocategory", // route name             "{controller}/{action}/{classificationid}/{reviewid}/", // url parameters             new { controller = "school", action = "edit", classificationid = "sbp", reviewid = "sar" } // parameter defaults         );          routes.maproute(             "schoolroute", // route name             "{controller}/{action}/{schoolid}/{reviewid}/{categoryid}/", // url parameters             new routevaluedictionary { { "action", "index" }, { "schoolid", urlparameter.optional }, { "reviewid", urlparameter.optional }, { "categoryid", urlparameter.optional } } // parameter defaults         ); 

and here controller signatures edit action:

    public actionresult edit(string schoolid, string reviewid) {}      public actionresult edit(string schoolid, string reviewid, int categoryid) {} 

the first edit action add default categoryid , forward second edit action.

my problem when try build actionlink in index view, following url:

http://localhost:21271/school/edit?classificationid=sbp&reviewid=sar 

where should have

http://localhost:21271/school/edit/sbp/sar/ 

the code actionlink

<%: html.actionlink("edit", "edit", new { item.classificationid, item.reviewid}) %> 

i'm starting feeling know less routing thought, of tutorials can find focus on routes , don't cover complicated. there tutorials cover sort of routing trying do?

edit:

got new routing issue, thought i'd try posting here first rather creating new thread.

i have following actionlink on edit page:

<%: html.actionlink(model.categories[i].name, "edit", new { acadperiod = model.acadperiod, classificationid=model.classificationid, reviewid=model.reviewid, categoryid=model.categories[i].category_id })%> 

which results in following url:

http://localhost:21271/school/edit?classificationid=sbp&reviewid=sar&categoryid=2 

if run route debugger, following output.

matched route: {controller}/{action}/{acadperiod}/{id} generated url: /school/edit/1011/sbp/sar/2 using route "{controller}/{action}/{acadperiod}/{classificationid}/{reviewid}/{categoryid}" 

however, in routes table, says {controller}/{action}/{acadperiod}/{classificationid}/{reviewid}/{categoryid} doesn't match?

it seems telling me 2 different things on same page.

this routes in global.asax stand:

        routes.maproute(             "schoolroute1",             "{controller}/{action}/{acadperiod}/{classificationid}/{reviewid}/{categoryid}",             new { controller = "school", action = "edit", acadperiod = "1011", categoryid = "1" }         );          routes.maproute(             "schoolroutenocategory",             "{controller}/{action}/{acadperiod}/{classificationid}/{reviewid}",             new { controller = "school", action = "edit", acadperiod = "1011", categoryid = "1" }         );          routes.maproute(             "schoolroute",             "{controller}/{action}/{classificationid}/{reviewid}/{categoryid}",             new { controller = "school", action = "edit", categoryid = "1" }         );           routes.maproute(             "schoolindex", // route name             "{controller}/{action}/{acadperiod}/{id}", // url parameters             new { controller = "school", action = "index", acadperiod = "1011", id = urlparameter.optional } // parameter defaults         );          routes.maproute(             "schoolindex1", // route name             "{controller}/{action}/{acadperiod}", // url parameters             new { controller = "school", action = "index", acadperiod = "1011" } // parameter defaults         );          routes.maproute(             "default", // route name             "{controller}/{action}/{id}", // url parameters             new { controller = "home", action = "index", id = urlparameter.optional } // parameter defaults         ); 

any ideas?

firstly, routes evaluated in order top bottom. first route have listed match anything additional routes never considered.

this means specific routes should go @ top. , default, "catch-all" route should go @ bottom.

i think route want (are second & third route supposed related?):

routes.maproute(     "schoolroute",     "{controller}/{action}/{schoolid}/{reviewid}/{categoryid}",     new { controller = "school", action = "edit", categoryid = "1" } ); 

if it's not optional , there's no default value, there's no need list in third line of route declaration.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -