简体   繁体   English

ASP.NET MVC:不确定如何进行这些路由

[英]ASP.NET MVC : Not sure how to make these routes

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') 这就是我所追求的...(假设我正在做一个“ stackoverflow网站”)

/                        <-- 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 :) ) (而且不。我绝对不是在做一个stackoverflow网站:))

cheers! 干杯!

(gawd i find dis all so confusing at times). (天哪,我发现dis有时如此令人困惑)。

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) {
    //...
  }
}

I would change the last url to /question/view/{subject}. 我会将最后一个网址更改为/ question / view / {subject}。 Futher Create 3 controllers: 进一步创建3个控制器:

  • PageController 的PageController
  • TagController TagController
  • QuestionController QuestionController

in Global.asax create those routes,(take example at the default route) 在Global.asax中创建这些路由,(以默认路由为例)

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM