开发者

asp.net MVC partial with dynamic inherits class?

开发者 https://www.devze.com 2022-12-09 14:16 出处:网络
I have a partial view that is shared between two c开发者_运维百科ontrollers and I\'m trying to find a way to change what it inherits from depending on which view it is being called from or which contr

I have a partial view that is shared between two c开发者_运维百科ontrollers and I'm trying to find a way to change what it inherits from depending on which view it is being called from or which controller.

IE:

my current partial is started like so:

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

and i would like it to also be able to inherit from another class because of needing the same info in two separate controllers

Any ideas?

Thanks


I think the best way is to introduce a common interface or an abstract class for MVCProject.Controllers.PurchasingOrderViewModel and your other model like:

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

精彩评论

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