라우팅을 사용하고 컨트롤러를 별도의 네임 스페이스에 보관하면됩니다. MapRoute을 사용하면 경로에 해당하는 네임 스페이스를 지정할 수 있습니다.
예
을 감안할 때이 컨트롤러 :
namespace CustomControllerFactory.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return new ContentResult("Controllers");
}
}
}
namespace CustomControllerFactory.ServiceControllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return new ContentResult("ServiceControllers");
}
}
}
다음과 같은 라우팅 추가
routes.MapRoute(
"Services",
"Services/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "CustomControllerFactory.ServiceControllers" } // Namespace
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "CustomControllerFactory.Controllers"} // Namespace
);
당신은 다음과 같은 응답
/서비스/홈 기대한다 - ServiceControllers
을
및 /홈 - 컨트롤러
당신은 [지역]을 사용하는 방법에 대해 생각 해본 적이 (https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/areas)? – CodingYoshi
영역을 사용하는 경우'BeginForm'은 다음과 같이'routeValues' 매개 변수에 영역 이름을 추가해야합니다 :'@using (Html.BeginForm ("SearchMotorcycle", "Motorcycle", new {area = "AreaName"}, FormMethod.Get , null))'. –