且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ASP MVC中进行自定义路由

更新时间:2022-12-11 15:41:54

忽略了也启用了属性路由.

Noticed that attribute routing is also enabled.

routes.MapMvcAttributeRoutes();

您也可以直接在控制器中设置路线.

you can also set up the route directly in the controller.

[RoutePrefix("ComicBooks")]
public class ComicBooksController : Controller {    
    [HttpGet]
    [Route("{PermaLinkName}")] //Matches GET ComicBooks/Spiderman
    public ActionResult ShowComicBook(string PermaLinkName){
        //...get comic book based on name
        return View(); //eventually include model with view
    }
}