c# - using generics for view model -
i have view i'd give model to, model can possible of 2 types. example:
public class super { public string name = "super"; } public class sub1 : super { public string name = "sub1"; } public class sub2 : super { public string name = "sub2"; } i'm trying experiment generics, , looking @ other questions see can following, however, declaring variable inside class correctly?
public class generic<t> t : super { public t subclass { get; set; } //is ok? } if ok, how add such class model view?
@model generic<??> <div>@model.subclass.name</div> is feasible, on right track, or kind of doing whole bunch of nothing?
just have view use super model:
@model super you'll able pass either sub1 or sub2 in since both inherit super.
Comments
Post a Comment