i have the following code that needs to evaluate its type although Im not sure how to do this in mvc 1? The show method at the bottom of the example highlights the problem where I need to evaluate whether the type is Car or Boat. Can anyone suggest how to do this please!
Many thanks
James
public interface IPanel
{
string Name { get; }
}
public class CarPanel : IPanel
{
public string Name
{
get { return "Hello Car"; }
}
}
public class BoatPanel : IPanel
{
public string Name
{
get { return "Hello Boat"; }
}
}
...
var list = new List<IPanel>();
list.Add(new BoatPanel());
list.Add(new CarPanel());
// In the view
foreach (var p in ViewData.Model.Panels)
{
<% Html.RenderAction<PanelController>(x => x.Show()); %>
}
// PanelController
public ActionResult Show()
{
var model = <T> // Problem: Am I a Boat or Car?
Use the
isoperator.The is operator is used for checking if a generic object is of a desired type.
Hope it helps 🙂