Question

i'm trying to make the following routes .. and currently i'm going about this in a really long way.. ie. one route instance for EACH route.

this is what i'm after... (assuming i'm doing a 'stackoverflow website')

/                        <-- root site
/page/{page}             <-- root site, but to the page of questions.
/tag/{tag}/page/{page}   <-- as above, but the questions are filtered by tag
/question/ask            <-- this page :P
/question/{subject}      <-- reading about a question

(and no.. i'm most definitely not doing a stackoverflow website :) )

cheers!

(gawd i find dis all so confusing at times).

Was it helpful?

Solution

For your third one, I'd do something like this:

routes.MapRoute("page-tag", "tag/{tag}/page/{page}", new {controller="question", action="FilterByTag"});

Your action method then could look like this:

public class QuestionController : Controller {
  public ActionResult FilterByTag(string tag, int page) {
    //...
  }
}

OTHER TIPS

I would change the last url to /question/view/{subject}. Futher Create 3 controllers:

  • PageController
  • TagController
  • QuestionController

in Global.asax create those routes,(take example at the default route)

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top