开发者

How do I allow extra text after my URLs in ASP.NET MVC?

I have this sole route in my app:

routes.MapRoute(
    "Default",                            
    "{controller}/{action}/{id}",         
    new { controller = "Home", action = "Index", id = ""} 
);

This works great for URLs like:

/Blah/Index

/Blah/Create

/Blah/Details/5

I want to add text to that last one like SO does:

/Blah/Details/5/Page-Title-Here-Or-Whatever

So my question is:

What should my routes look like to 开发者_JS百科accomplish this? (or if it doesn't have anything to do with routes...what do I do?)


MSDN Link: http://msdn.microsoft.com/en-us/library/cc668201.aspx

routes.MapRoute( 
    "Default",                             
    "{controller}/{action}/{id}/{*allTheRest}",          
    new { controller = "Home", action = "Index", id = "", allTheRest=""}  
); 

Function signature should be similar to

    public ActionResult MyAction(int? id, string rest)
    {
        this.TempData["ID"] = id ?? -1000;
        this.TempData["REST"] = rest ?? "Not Provided";
        return View();
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜