I have a view that I'd like to give a model to, but the model can be a 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 to experiment with generics, and looking at some other questions I see I can do the following, however, am I declaring the variable inside the class correctly?
public class Generic<T> where T : Super {
public T SubClass { get; set; } //is this ok?
}
if this is ok, how would I add such a class as the model to a view?
@model Generic<??>
<div>@Model.SubClass.Name</div>
is this even feasible, am I on the right track, or am I just kind of doing a whole bunch of nothing?
TwithSuper.Namewill hide the member in the base class and possibly won't behave as you expect.