Tôi có một bộ điều khiển tên Registration
và một phương pháp hành động trong nó như sau:không thể ánh xạ một con đường cho một bộ điều khiển cụ thể trong MVC 4
public JsonResult GetReqs(GridSettings gridSettings, int rt)
{
...//whatever
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
Vì vậy, tôi đã thêm một tuyến đường và bây giờ RouteConfig.cs
của tôi là như thế này :
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "RegReq",
url: "{Registration}/{GetReqs}/{rt}",
defaults: new { controller = "Registration", action = "GetReqs", rt = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Tuy nhiên tôi không thể truy cập rt
tham số và phương pháp hành động GetReqs
không được gọi là (tôi đặt một breakpoint vào nó nhưng không có gì xảy ra). Sai lầm ở đâu?
Edit: liên kết ví dụ tôi đã cố gắng: ~/Registration/GetReqs/1
Đã sửa lỗi! cảm ơn rất nhiều – AminSaghi