Aspx page in MVC3

后端 未结 2 1313
执笔经年
执笔经年 2021-01-24 12:58

I am developing an MVC3 application using Visual Studio 2010.

I have an aspx page that I want to display as a result of a controller action.

I added this action

相关标签:
2条回答
  • 2021-01-24 13:44

    You don't use server side controls in ASP.net MVC.

    You use the HTML Helper methods:

    <%= Html.TextBox("TextBox1") %>
    

    The server-side controls are not supported in MVC because MVC does not have the concept of ViewState.

    Edit:

    If you need to integrate MVC and WebForms, then you will need to create standalone Web Form pages. These will not be "Views" in your MVC application. You can then create routes to these web form pages by doing the following in your Global.asax:

    public static void RegisterRoutes(RouteCollection routes) {
        routes.MapPageRoute(
            "WebFormProducts",
            "/products/{category}",
            "~/WebForms/Products.aspx"
        );
    }
    

    Now when you go to /products/beverages it will actually go to your Products.aspx page that lives in the WebForms folder.

    You create this Products.aspx file the same as a normal webforms page. The disadvantage to this (if nothing has changed) is you can not share a Master page / Layout page so you will have to duplicate any layout and create a .master to make the pages look similar.

    0 讨论(0)
  • 2021-01-24 13:53

    Easy way to use aspx page on mvc controller for rdlc view

    public ActionResult RdlcReport( )
    {
        IHttpHandler page = (IHttpHandler)System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath("~/Report/ReportDataViewer.aspx", typeof(Page));
        HttpApplication controllerContextHttpContextGetService = (HttpApplication)ControllerContext.HttpContext.GetService(typeof(HttpApplication));
        page.ProcessRequest(controllerContextHttpContextGetService.Context);
        return new EmptyResult();
    }
    
    0 讨论(0)
提交回复
热议问题