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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:12:59+00:00 2026-06-04T21:12:59+00:00

I have a list: public List<MyModel> MyModels { get; set; } How would I

  • 0

I have a list:

public List<MyModel> MyModels { get; set; }

How would I display one piece of information from one object within that list using Razor syntax?

I want to do something like:

@Html.Display(MyModel.Select(o => o.objectId = selectedObjectVal).FirstOrDefault().TextThatNeedsDisplayed)

But that does not compile. How would I properly display the information I want?

When I use the updated code above (retrieved from an answer below) I get the following error: CS1061: ‘int’ does not contain a definition for ‘grade’ and no extension method ‘grade’ accepting a first argument of type ‘int’ could be found (are you missing a using directive or an assembly reference?). The IntelliSense is giving me options of “Compare To” “Equals” “GetHashCode” etc. . .


Update:

If I do a .ToString()) at the end in place of “TextThatNeedsDisplayed” (and change from @Html.Display to @Html.Raw) it returns the data that it is searching by – literally what is stored at “o.objectId = selectedObjectVal” . I don’t know why this is – shouldn’t it be trying to turn the entire MyModel into a string? Still not showing TextThatNeedsDisplayed.

  • 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-04T21:13:00+00:00Added an answer on June 4, 2026 at 9:13 pm

    Assuming that your Model is a list of (View)Models you could access a property of one model in many ways.

    if the list is the model for your razor view:

    @Html.DisplayFor(model => model[0].TextThatNeedsDisplayed)
    

    or just select one object from your list:

    @Html.Display(MyModel.First().TextThatNeedsDisplayed)
    

    Hope I understood your question right.

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

Sidebar

Related Questions

I have a model: public class MyModel { int id { get; set; }
I have a list of images in my control public List<BitmapImage> Images { get;
I have an ASP.NET WebService that returns an object of List public class Students
I have an Expression that is used to get a list of items from
Let's say I have an object with a list of int as one of
This is my Model: public class MyModel{ public string Name { get; set; }
I have a static list: public static List<IMachines>mList =new List<IMachines>(); The list intakes two
in Android, I have list that I fill using the following code @Override public
I have code that looks like this: template<class T> class list { public: class
I'm using EF with MVC3. I have a model with a custom list: public

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.