I have a View that is displaying data from a list of object that I send it. These objects are all the same base class, but can be a number of different derived types. so, I have:
class Item { public string Description {get;set;}
class VideoItem : Item { public int VideoId {get;set;} }
class PdfItem : Item { public pdfLocation {get;set;} }
I display these all in a single list and would like to be able to have one Controller Method that I can call that will handle each one of these. Having overloads for the method would be fine as well.
I have it wired in as an ActionLink, but I can’t figure out how to pass the entire object to the controller. When I try to pass the class, it only passes the classname (i’m assuming it’s using the .ToString() method on it.
I could use some sort of unique id and then requery the database and recreate the object, but it seems that if I already created the object, I should be able to pass it to a controller intact, no?
Maybe ActionLink isn’t the best solution. I dont care how the controller gets called.
ideas?
Something like this can work for you (assuming you want to display the content of each item as a link):
Create a custom HtmlHelper method:
Use it like this (assuming itemList is a
List<Item>type list):NOTE: i did not run this code so some tweaking may be necessary.