2014-02-10 2 views
0

나는 2 개의 다른 지역을 가진 asp.net mvc 프로젝트를 가지고있다.지정된 영역에서 asp.net mvc 프로젝트 실행

enter image description here

여기 아래 RouteConfig.cs 내 코드입니다.

routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
      namespaces:new[]{"Sample1.Controllers"} 
     ); 

내가 실행할 때 Sample1을 기본 프로젝트로 보거나 그 반대로하고 싶습니다. 하지만 그것은 내가 아래에 명시된 오류를 준다.

Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.The request for 'Home' has found the following matching controllers:AreaSample.Areas.Sample1.Controllers.HomeController AreaSample.Areas.Sample2.Controllers.HomeController 

지정한 네임 스페이스가 작동하지 않습니다. 또한 Sample1AreaRegistration.cs와 비슷합니다.

context.MapRoute(
      "Sample1_default", 
      "Sample1/{controller}/{action}/{id}", 
      new { controller="Home", action = "Index", id = UrlParameter.Optional } 
     ); 

어떻게 문제를 해결할 수 있습니까?

답변

0

기본 경로에 지역 특정 네임 스페이스를 제공해서는 안됩니다. RouteConfig.cs 파일에 Sample1.Controller가있는 대신 AreaSample.Controllers로 변경하십시오. 각 AreaRegistration 파일에 네임 스페이스를 추가하십시오.

  • Sample1을 기본 영역으로 지정하려면 별도의 프로젝트라고 가정합니다. 그래서 그것을 구성 관리자에 추가하십시오. 솔루션 구성에서 Sample1 프로젝트를 선택하고 응용 프로그램을 실행하십시오.

  • 또는 프로젝트 속성에서 특정 페이지를 기본값으로 추가하십시오. 프로젝트 >> 속성 >> 웹 >>을 오른쪽 클릭하십시오. 특정 페이지 옵션을 선택하고 Areaname/ControllerName/ActionName을 입력하십시오.

+0

답장을 보내 주셔서 감사합니다. 그러나 나는 당신의 첫번째 문제를 이해하지 못합니다. 또한 두 번째 배포 때문에 나를 위해 작동하지 않습니다. 실제로 RouteConfig.cs를 변경하면 아무 문제없이 배포하려는 영역이 기본 프로젝트가 될 수 있기를 원합니다. – Bora

0

가장 좋은 해결책은 Sample1을 별도의 영역으로 만들지 않는 것입니다. 그러나 Sample1은 기본 템플릿과 같이 프로젝트의 루트 Controllers/Views가됩니다. 이 같은 2 영역을 갖고 싶어

하지만, 그때는 아마 이런 식으로 뭔가를 할 수 :

는 AreaRegistration 클래스의 네임 스페이스를 지정 마십시오.

RouteConfig.cs 클래스의 네임 스페이스를 지정하지 마십시오.

RouteConfig.cs에서 기본 영역 값도 제공해야합니다.

routes.MapRoute(
     name: "Root", 
     url: "", 
     defaults: new { area = "Sample1", controller = "Home", action = "Index" } 

routes.MapRoute(
     name: "Default", 
     url: "{controller}/{action}/{id}", 
     defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
    ); 
+0

AreaRegistration 클래스에서 나는 네임 스페이스를 넣는다. 또한 당신처럼 내 코드를 변경했지만 stil 작동하지 않습니다. – Bora

관련 문제