我設法讓我的家庭控制器只使用操作名稱來訪問它,但只要我添加另一個控制器並嘗試通過在我的Home路由聲明中添加另一個路由聲明來執行相同的操作,所有路由默認爲Home控制器。MVC路由 - 我想在URL中沒有控制器的多個{action}/{id}路由
routes.MapRoute("HomeTest", "{action}/{id}", new { controller = "Home", action = "TestHome", id = UrlParameter.Optional });
routes.MapRoute("TestTest", "{action}/{id}", new { controller = "Test", action = "Test", id = UrlParameter.Optional });
public class HomeController : Controller
{
public ActionResult TestHome(int? id)
{
return View();
}
}
public class TestController : Controller
{
public ActionResult Test(int? id)
{
return View();
}
}
有沒有什麼辦法可以訪問兩個控制器,而不在url中包含控制器名稱?
我也有默認路線,如果這有什麼區別。它在這兩條路線下。