我有这个网址http://example.com/Book/Details?Bookid=15这个网址
我想像这样http://example.com/Book/Details/BlackBook/
重写网址请帮助谢谢
答案 0 :(得分: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)
内创建BookController
操作方法以获得相同的结果