Attribute Routing trong ASP.NET MVC là gì?
Attribute Routing trong ASP.NET MVC là gì?
Attribute Routing cho phép khai báo route bằng attribute ngay trên controller/ action.
// MVC 5: bật
routes.MapMvcAttributeRoutes();
[RoutePrefix("orders")]
public class OrdersController : Controller
{
[Route("")] public ActionResult Index() => View(); // /orders
[Route("{id:int}")] public ActionResult Details(int id) => View(); // /orders/5
[Route("{id:int}/items/{sku}")] public ActionResult Item(int id, string sku) => View();
[HttpPost, Route("~/checkout")] public ActionResult Checkout() => ...; // ~ bỏ qua prefix
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.