4

I found questions and good answers on how to inclue asp.net mvc inside webforms (like this), but I'm needing to reuse some webforms inside asp.net mvc.

How to do that ?

I was thinking in a solution where a call to a partial view (or a static helper) would render webforms as partialview inside a Razor View (eigther actions).

Is it possible ?

Community
  • 1
  • 1
Luciano
  • 2,695
  • 6
  • 38
  • 53
  • 2
    What are you trying to do? WebForms and the server side controls they contain are usually tightly coupled to ViewState and PostBack which are notions that no longer exist in ASP.NET MVC. So even if you find a way to render a classic WebForm as a partial inside a Razor view, unless this WebForm is pretty static and doesn't contain lots of server side controls it will be useless. Not to mention that most of the controls will probably complain because they need to be hosted in a `
    ` with `runat="server"` which obviously doesn't exist in ASP.NET MVC.
    – Darin Dimitrov Apr 13 '12 at 21:27
  • Is using `iframe` elements an option? It's icky, but it will allow this, fsvo allow. As Darin points out, WebForms *requires* a specially setup environment. –  Apr 13 '12 at 21:28
  • 2
    I back up the `iframe` approach. Even if it is icky it is reliable and guaranteed to work. In addition to that it allows you to have the 2 as separate applications and thus not *polluting* your ASP.NET MVC application with *legacy stuff*. Anyway there's no general answer to this question. It will very much depend on the exact scenario and the exact contents of the WebForm that you are trying to reuse as well as the level of interaction you need between the two. – Darin Dimitrov Apr 13 '12 at 21:30
  • Would using `Server.Execute` to load the web form be another possible solution? – James Johnson Apr 13 '12 at 21:36
  • All solutions and approaches are possible. I'm looking for alternatives, for the time being. We`ll study, compare, and try some of them, maybe one of them would be adopted as the more convenient solution to the project. – Luciano Apr 13 '12 at 22:27

1 Answers1

4

Maybe you could load the WebForm through jquery ajax:

$.ajax({ url : 'http://tempuri.org/webfrom.aspx',
         type: 'GET',
         cache : false,
         success : function(data){
             $("#yourcontainer").html(data);
         }
 });
Preben Huybrechts
  • 5,853
  • 2
  • 27
  • 63