3

I am building a new ASP.NET MVC 3 application. In this application, I would like to display an old WebForms user control (.ascx/.ascx.cs) in an overlay in my new MVC razor app as a partial view. I cant find anything about doing this on the web. Can anyone tell me if this is possible, and if so point me to some documentation? Thanks.

Dave Alperovich
  • 32,320
  • 8
  • 79
  • 101
user1373121
  • 999
  • 4
  • 13
  • 22

3 Answers3

4

It is very bad practice to do such a thing. However this could be achieved by the following code:

@Html.Partial("_Foo")

Then in your _Foo partial view, you could have the following:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%@ Register Assembly="SomeAssembly" Namespace="SomeNs" TagName="foo" %>

<foo:SomeControl runat="server" ID="fooControl" />

Hope this helps. Have a look at this question:

Community
  • 1
  • 1
skub
  • 2,266
  • 23
  • 33
3

The long answer involves 'yes you can, but....'

The short answer is, you shouldn't.

Without knowing the specifics of your .ascx file, you can render a partial using

@Html.Partial(PageName)

But, if you have any server controls they will not work. MVC doesn't support the same kind of call back control state functionality. So, you are using any thing resembling

<asp:Button runat=server />

then you're far better off re-factoring your partial.

Dave Alperovich
  • 32,320
  • 8
  • 79
  • 101
1

I'm working on something similar. I've found these links that might help you.

http://www.codemag.com/article/1009061

How do I render a remote ReportViewer aspx page in MVC4?

How can I use a reportviewer control in an asp.net mvc 3 razor view?

Community
  • 1
  • 1
dieKoderin
  • 1,552
  • 3
  • 19
  • 39