2

我有这个网址http://example.com/Book/Details?Bookid=15这个网址

我想重写这样的网址http://example.com/Book/Details/BlackBook/

4

1 回答 1

4

将以下路由添加到 global.asax.cs RegisterRoutes:

routes.MapRoute(
            "Book By Name",
            "Book/Details/{bookName}",
             new { controller = "Book", action = "BookDetails" }
        );

你需要一个BookController带有以下 Action 的方法:

public Book BookDetails(string bookName)
{
    // Your logic here to get a book by name and return it
}

或者,您可以使用默认路由并Details(string id)在 a 中创建一个操作方法BookController以实现相同的结果

于 2012-10-03T11:12:06.317 回答