如何使用ASP.NET MVC的路由功能处理类似下面的内容:
http://localhost/users/{username}/bookmarks/ - GET
http://localhost/users/{username}/bookmark/{bookmarkid} - PUT
其中列出了{username}中用户的书签。
由于
答案 0 :(得分:5)
您可以在动作方法
上使用[AcceptVerbs]属性public class BookmarksController : Controller
{
[AcceptVerbs(HttpVerbs.Get)]
public void Bookmarks(string user)
{
//add your bookmark
}
[AcceptVerbs(HttpVerbs.Post)]
public void Bookmarks(string user, int? id)
{
//add your bookmark
}
}
答案 1 :(得分:4)
首先你需要在global.asax
中创建一个新路由routes.MapRoute("Bookmarks", "{controller}/{user}/{action}/{id}");
然后添加新动作
public class UsersController : Controller
{
[AcceptVerbs("Post")]
public void Bookmarks(string user, int? id)
{
//add your bookmark
}
}