1 Replies - 4715 Views - Last Post: 18 November 2012 - 09:10 PM

#1 solomon201  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 19-November 07

Unexpected Result from foreach loop in MVC 3 Razor View

Posted 14 November 2012 - 08:16 AM

I have a loop in my razor view as
below
<div>
@foreach(var inmate in Model)
{
@inmate.inmateid
@inmate.inmateid
}
</div>
My Model is an IEnumerable of inmates
containing 2 inmate objects. But the
result I am getting in my browser is
6
6
7
7
Instead of
6
7
Please can someone tell me why this is
the case?
Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Unexpected Result from foreach loop in MVC 3 Razor View

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 441
  • View blog
  • Posts: 1,488
  • Joined: 28-April 09

Re: Unexpected Result from foreach loop in MVC 3 Razor View

Posted 18 November 2012 - 09:10 PM

it's doing exactly what you told it to do, showing the inmate id twice foreach inmate object in your Model
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1