开发者

How set attribute to MVC2 user control type in declarative way

开发者 https://www.devze.com 2022-12-22 14:27 出处:网络
How can I set attribute to MVC2 user control defined in single file with content: <%@ Control Language=\"C#\" Inherits=\"System.Web.Mvc.ViewUserControl\" %>

How can I set attribute to MVC2 user control defined in single file with content:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

I'm searching declarative solution. Something like this:

<%[DefaultProperty("Items")]%>
<%@ Control 开发者_开发知识库Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

Thanks.


You would need to create a new class that inherits from ViewUserControl

public class SpecialAttribute : Attribute { }

[Special]
public class MyUserControl : ViewUserControl
{

}

And then in your partial view you would use the Inherits attribute like this:

<%@ Control Language="C#" Inherits="MvcApplication1.CustomViews.MyUserControl" %>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号