Asp.net mvc 3 未在url中传递值
如果我浏览到URL localhost/Ajax/FindRooms/SOMEBUILDING。SOMEBUILDING未传递给FindRooms方法的selectedBuilding参数。它总是空的??我如何修复此问题,使其在POST和GET中都能工作?正如TA先生所建议的,其他路径会影响此问题。路由的顺序很重要 我把默认的路线放在末尾,就像一个符咒一样Asp.net mvc 3 未在url中传递值,asp.net-mvc-3,Asp.net Mvc 3,如果我浏览到URL localhost/Ajax/FindRooms/SOMEBUILDING。SOMEBUILDING未传递给FindRooms方法的selectedBuilding参数。它总是空的??我如何修复此问题,使其在POST和GET中都能工作?正如TA先生所建议的,其他路径会影响此问题。路由的顺序很重要 我把默认的路线放在末尾,就像一个符咒一样 //In Controller this is what I have public class AjaxController : C
//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 = "" }
);
你们还有其他的路线登记吗?注意路线注册的顺序,因为可以使用更通用的路线,而不是不太通用的路线。
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 }
);