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

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -