Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:50:47+00:00 2026-06-02T17:50:47+00:00

I have a View that is displaying data from a list of object that

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:50:49+00:00Added an answer on June 2, 2026 at 5:50 pm

    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:

    public static class LinkExtensions
    {
        public static MvcHtmlString CustomActionLink(this HtmlHelper htmlHelper, Item item )
        {
            MvcHtmlString returnString = "";
    
            if(item is VideoItem) 
            {
                VideoItem currentItem = item as VideoItem;
                returnString = htmlHelper.ActionLink(currentItem.VideoId, "Video", "Item");
            }        
            if(item is PdfItem) 
            {
                PdfItem currentItem = item as PdfItem;
                returnString = htmlHelper.ActionLink(currentItem.pdfLocation, "Pdf", "Item");
            }
            else
            {
                returnString = htmlHelper.ActionLink(currentItem.Description, "Item", "Item");
            }
    
            return returnString;
        }
    }
    

    Use it like this (assuming itemList is a List<Item> type list):

    <%= foreach(var item in itemList) { Html.CustomActionLink(item) } %>
    

    NOTE: i did not run this code so some tweaking may be necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view that takes data from my site and then makes it
I have an data transfer object called Report . These report objects are held
I have a gridview that is displaying data from a database using LINQ to
I have a view that is displaying a Drop down list using the HTML
I have a view that will be displaying downloaded images and text. I'd like
I have a view that contains two NSTextFieldCell s. The size at which these
I have a view that I would like to populate data when the next
I currently have a simple list view adapter that holds two rows of text.
I have a very simple page that is displaying canned data. I experienced this
I have a catalogue application in iOS 5 that is downloading data from XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.