Mixing MVC and Webform in same web application

Last post 05-10-2008 11:32 AM by albertpascual. 5 replies.

Sort Posts:

  • Mixing MVC and Webform in same web application

    05-04-2008, 5:06 PM
    • Loading...
    • vlangber
    • Joined on 01-11-2005, 7:16 AM
    • Posts 40

    Scott Guthrie mentioned in one of his MVC blog posts that it is possible to combine MVC and webforms in the same application. I've tried that, but I get lots of errors in the webforms.

     What I'm trying to do: I have a asp.net cms, with an edit part where I need to continue to use webforms. I want to use MVC for the website itself. I've copied all relevant files from the webforms application into an empty MVC application(it worked before I started copying files), and then I've added a few lines in the web.config file on the root of the application.

    When I try to build the solution, I get lots of errors like this: "The name 'txtRank' does not exist in the current context", in the codebehind files of the webform aspx files. txtRank is a regular textbox: <asp:TextBox ID="txtRank" runat="server"></asp:TextBox>.

    What am I missing?

  • Re: Mixing MVC and Webform in same web application

    05-04-2008, 9:36 PM

    I believe, however I have not try it, you can mix some MVC in a WebForm project, howver I don't see how can you do it backwards, mixing webforms in an existing MVC project. I have not try it just yet. Hanselman has an article about it http://www.ayende.com/Blog/archive/2007/06/01/MVC-in-WebForms-The-impossible-fight-to-get-rid-of.aspx

    Cheers
    Al
    My Blog
    Follow me
    Please click on 'Mark as Answer' if this post answered your question!
  • Re: Mixing MVC and Webform in same web application

    05-07-2008, 4:51 AM
    • Loading...
    • vlangber
    • Joined on 01-11-2005, 7:16 AM
    • Posts 40

    Please correct me if I'm wrong, but the article from Hanselman is not about ASP.Net MVC, but using MVC in ASP.Net before ASP.Net MVC was launched.

    Anyone got suggestions on how to mix ASP.Net MVC and webforms in the same website?

  • Re: Mixing MVC and Webform in same web application

    05-08-2008, 8:53 AM
    • Loading...
    • benricho
    • Joined on 06-17-2002, 6:22 PM
    • Sydney, Australia
    • Posts 7
    It sounds to me like your pageName.aspx.designer.cs files didn't get copied across to the new solution.
  • Re: Mixing MVC and Webform in same web application

    05-10-2008, 3:15 AM
    • Loading...
    • sawbill
    • Joined on 03-16-2004, 4:00 AM
    • Posts 13

    It could be as simple as you copied the webforms from a website project where as MVC uses Web Application projects. You could try right clicking on the page file and select "convert to web application" (or something like that). That will creates the xxx.aspx.designer.cs and populate it with the control member fields.

  • Re: Mixing MVC and Webform in same web application

    05-10-2008, 11:32 AM

    I just did add a webform control inside a MVC project without any problem, you need to add the <form> and then the control with the divs to position the contro where you wanted.

    It's great that I can mix webfoms and MVC, not the is the idea solution, but is great to know that you can do it and it works great.

    Cheers
    Al
    My Blog
    Follow me
    Please click on 'Mark as Answer' if this post answered your question!
Page 1 of 1 (6 items)