How to display WebForms .ascx as partial view in MVC 3

后端 未结 3 1903
孤城傲影
孤城傲影 2021-01-06 13:56

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 a

3条回答
  •  隐瞒了意图╮
    2021-01-06 13:58

    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" %>
    <%@ Register Assembly="SomeAssembly" Namespace="SomeNs" TagName="foo" %>
    
    
    

    Hope this helps. Have a look at this question:

    • MVC 3: Add usercontrol to Razor view

提交回复
热议问题