2017-10-10 1 views
2

web.config 변경 및 필요한 어셈블리 추가와 같은 모든 단계를 수행했습니다.
ASP.Net and Webforms in Harmony MVC3을 webforms 프로젝트에 설치하고 컨트롤러를 구현하고 Global.asax의 Application_Start 메소드에 해당 경로를 등록했습니다.MVC3을 웹 폼에 통합 - MVC 라우팅이 작동하지 않음

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

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

여기에 나는 그것의 행동 (즉/홈/색인)하지만 404 찾을 수 없음 오류가 전화를하려고 컨트롤러

public class HomeController : Controller 
{ 
    // 
    // GET: /Default1/ 

    public ActionResult Index(int? id) 
    { 
     ViewData["Message"] = "Hello from Home controller"; 
     return View(); 
    } 

} 

입니다.

다른 .aspx 양식에 대해 등록 된 경로가 정상적으로 작동합니다.

routes.Add("Home", new Route("Home", new RoutingHandler("/Default.aspx"))); 

모든 것이 잘 작동하지만 (집/색인)가 표시되지 않습니다.

답변

1

MVC과 같이 웹 프로젝트에 Area을 추가하면됩니다. 그럼 당신은 이제 예를 Home위한 컨트롤러를 추가하고보기를 추가

MVCAreaRegistration.RegisterAllAreas(RouteTable.Routes);

아래 같은 Area Global.asax.cs에서 클래스 Global에서 파일의 기능 protected void Application_Start(object sender, EventArgs e) 기능 Index 말 것을 등록해야합니다. 인덱스 작업 메서드에 중단 점을 놓고 응용 프로그램을 실행하십시오. url 유형 ".../MVC/Home/Index"에서 중단 점이 발생합니다.

관련 문제