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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:11:50+00:00 2026-06-13T10:11:50+00:00

ViewBag.EquipmentList = myInventoryEntities.p_Configurable_Equipment_Request_Select(Address_ID, false).Select(c => new { Value = c.Quantity + + c.Device_Name +

  • 0
ViewBag.EquipmentList = myInventoryEntities.p_Configurable_Equipment_Request_Select(Address_ID, false).Select(c => new { Value = c.Quantity + " " + c.Device_Name + " (s)", ID = c.Device_ID.ToString() }).ToList();

In Razor i want to do the following

@ViewBag.EquipmentList.Count

But Count is always == 1

I know i can iterate in a foreach but would rather a more direct approach.

Perhaps I am conceptually off?

  • 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-13T10:11:51+00:00Added an answer on June 13, 2026 at 10:11 am

    EDIT: Okay, so now it seems like you’ve got past Count not executing:

    But Count is always == 1

    Sounds like you’re always fetching a list with exactly one entry in. If that’s unexpected, you should look at why you’re only getting a single entry – start with debugging into the code… this doesn’t sound like a Razor problem at all.


    If your value were really a List<T> for some T, I believe it should be fine. The expression ViewBag.EquipmentList.Count would evaluate dynamically at every point.

    In other words, if you’re really, really using the assignment code shown, it should be okay.

    If, however, the value is just some implementation of IEnumerable<T> which doesn’t expose a Count property, then you’d need to use the Enumerable.Count() extension method – and you can’t use normal “extension method syntax” with dynamic typing. One simple fix would be to use:

    Enumerable.Count(ViewBag.EquipmentList)
    

    … which will still use dynamic typing for the argument to Enumerable.Count, but it won’t have to find the Count() method as an extension method.

    Alternatively, make sure that your value really is a List<T>. If it’s actually an array, you should be able to change the code to use the Length property instead.

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

Sidebar

Related Questions

My controller action code: ViewBag.country = from p in CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures) select new
this is my select list: ViewBag.gov = new SelectList(entity.gouvernerat, Idgov, Nomg); And this is
this is my code: ViewBag.idprofesor = new SelectList(db.Profesor, IDProfesor, nombre); this code generate a
I have a ViewBag.People made up from a View; var query = db.Vw_INTERACTPEOPLE.Select(p =>
In my controller I use the following: ViewBag.ReferenceId = new SelectList(_reference.Get(00) .AsEnumerable() .OrderBy(o =>
I am using ViewBag value as follows : var date = @ViewBag.fromDateForEditMode $('#FromDate').val(date); All
I have the following : ViewBag.SomeEnumerable = new List<string>() { string1, string2 }; Now
I have the following code which works: ViewBag.Resources = New SelectList(db1.Tbl_Resources, Resource_ID, Resource_FirstName) I
I need to assign value from viewbag as one of the attribute of javascript
How can I store a value in the ViewBag accessing it from javascript?

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.