Aspx page in MVC3

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 to the home controller.

// GET: /Home/EmployeePortal public ActionResult EmployeePortal() { return View(); } 

This is an aspx page.

 <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <!DOCTYPE html> <html> <head runat="server"> <title>EmployeePortal</title> </head> <body> <asp:TextBox ID="TextBox1" runat="server" /> <div> This is employee portal </div> </body> </html> 

When I launch the application, I can go to this page using the URL: http: // localhost: 3990 / Home / EmployeePortal

The problem is that when I have one or more server side controls on an aspx page, I get this error on the website. An error occurred while processing your request.

When I comment on a server side control from a page, it appears in order.

The aspx page has been added as an application for the application through the new menu.

I need an aspx page embedded in an MVC application, and so I am trying to use this aspx page.

I'm not sure what I'm doing wrong. Please help.

+1
source share
2 answers

ASP.net MVC does not use server-side controls.

You are using HTML Helper methods:

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

Server-side controls are not supported in MVC because MVC does not have a ViewState concept.

Edit:

If you need to integrate MVC and WebForms, you will need to create stand-alone web form pages. They will not be “Views” in your MVC application. You can then create routes to these web form pages by following these steps in your Global.asax application:

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

Now, when you go to / products / drinks, it really goes to your Products.aspx page, which is located in the WebForms folder.

You create this Product.aspx file just like a regular web form page. The disadvantage of this (if nothing has changed) is that you cannot split the page of the main page / layout so that you have to duplicate any layout and create .master so that the pages look the same.

+7
source

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

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
source

All Articles