MVC 3: Add usercontrol to Razor view

前端 未结 2 517
不知归路
不知归路 2020-12-01 12:57

I have a DLL that contain a user control inside, in the Web Form view i can easily use it by using

<%@ Register Assembly = \"...\" Namespace = \"...\" Ta         


        
2条回答
  •  感情败类
    2020-12-01 13:55

    You can't add server side controls to Razor views. In general it is very bad practice to do so anyways in an ASP.NET MVC application. Due to the heritage of WebForms view engine you could violate this rule but in Razor things have been made clearer.

    This being said you could still do some pornography in Razor and include a WebForms partial which will contain the user control (totally not recommended, don't even know why I am mentioning it but anyway):

    @Html.Partial("_Foo")
    

    where in _Foo.ascx you could include server side controls:

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

提交回复
热议问题