代码之家  ›  专栏  ›  技术社区  ›  Hasan Ali

将MVC3集成到webforms-MVC路由不起作用

  •  2
  • Hasan Ali  · 技术社区  · 7 年前

    我已经遵循了这个链接的所有步骤,包括网页。配置更改和添加所需的程序集。
    ASP.Net and Webforms in Harmony 我已将MVC3安装到webforms项目中,并实现了一个控制器,并在Global的Application_Start method中注册了其路由。尽快。

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

    这是控制器

     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 回复  |  直到 7 年前
        1
  •  1
  •   Ammar    7 年前

    您可以通过添加 Area 例如,在您的web项目中 MVC 地区 在里面 Global 中的类 Global.asax.cs 文件的功能 protected void Application_Start(object sender, EventArgs e) 功能如下

    MVCAreaRegistration.RegisterAllAreas(RouteTable.Routes);

    现在添加一个控制器,例如 Home 并添加一个视图,比如说 Index