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 8917435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:28:57+00:00 2026-06-15T05:28:57+00:00

I have a requirement to pass an IEnumerable<Object> to an MVC view and have

  • 0

I have a requirement to pass an IEnumerable<Object> to an MVC view and have the view cast this to a strongly typed object and display it accordingly.

This appears to be having a performance impact vs. passing it down as a IEnumerable of MyCustomObject.

foreach (var item in Model.Items)
{
    var current = (MyCustomObject) item;
    <p>@current.Submitted</p>
}

My questions are

  1. Should I cast the entire IEnumerable of Objects to IEnumerable of MyCustomObject?
  2. How can I improve the performance of this operation?
  3. If this is not good practice, what’s the best way to pass a “variable” type for my Items collection, which could be a collection of any type of custom object?
  • 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-15T05:28:58+00:00Added an answer on June 15, 2026 at 5:28 am

    Initially, you could use Cast on the entire collection:

    foreach (var item in Model.Items.Cast<MyCustomObject>()){}
    

    If your types will all inherit from a base type, say MyCustomObject, then your model should specify this, e.g.

    public class MyViewModel<T> where T : MyCustomObject, new() 
    {
        public IEnumerable<T> Items { get; set; }
    }
    

    You would need to ensure that any types you wished to add to your items collection inherited from the base MyCustomObject type

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

Sidebar

Related Questions

I have a requirement to pass credentials from one Microsoft .NET Web Application to
The question I have is exactly same in requirement as How to pass mouse
I have requirement to disable copy/paste/cut operations on a textbox. For this purpose I
I have the requirement to support different Master pages on my application (ASP.NET MVC).
I have a feeling this should be a common requirement, but I can't work
I have a requirement to pass bulk data between a .NET (c#) application and
I have a requirement where I have to pass some values into the next
I have a requirement to do the following. Pass a set of variables from
I have a string that is failing to pass the below requirement:- $uid =
I have requirement where some times I would like to load children as well

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.