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 ?

5
  • 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 <form> with runat="server" which obviously doesn't exist in ASP.NET MVC. Commented Apr 13, 2012 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. Commented Apr 13, 2012 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. Commented Apr 13, 2012 at 21:30
  • Would using Server.Execute to load the web form be another possible solution? Commented Apr 13, 2012 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. Commented Apr 13, 2012 at 22:27

1 Answer 1

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);
         }
 });
Sign up to request clarification or add additional context in comments.

2 Comments

Very nice! An easy way to embed ASPX inside the MVC layout.
Yeah ! But is similar to calling it directly from a view. Embedding the result at server-side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.