//In Controller this is what I have
public class AjaxController : Controller
{
[AcceptVerbs(new string[]{"GET"})]
public ActionResult FindRooms(string selectedBuilding)
{
return Json(new { Room = "x"}, JsonRequestBehavior.AllowGet);
}
}
//In Global.asax.cs I have
routes.MapRoute
(
"AjaxRoute1",
"Ajax/FindRooms/{selectedBuilding}",
new { controller = "Ajax", action = "FindRooms", selectedBuilding = "" }
);
如果我浏览到URL localhost / Ajax / FindRooms / SOMEBUILDING。 SOMEBUILDING未传递给FindRooms方法的selectedBuilding参数。它总是空的?我如何解决这个问题,以便它在POST和GET中都有效?
答案 0 :(得分:0)
正如TA先生建议其他路线影响这一点。路由的顺序很重要。
我把默认的路线路线放在最后,就像一个魅力。!!
routes.MapRoute
(
"AjaxRoute1",
"Ajax/FindRooms/{selectedBuilding}",
new { controller = "Ajax", action = "FindRooms", selectedBuilding = "" }
);
routes.MapRoute
(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);