Problem with foreach loop in MVC 3 Razor View
-
I have a loop in my razor view as below
@foreach(var inmate in Model) { @inmate.inmateid @inmate.inmateid }
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
-
I have a loop in my razor view as below
@foreach(var inmate in Model) { @inmate.inmateid @inmate.inmateid }
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
Because you enumerating collection, and for each item You are writing this item twice. If you want it just once remove one @inmate.inmateid from inside foreach loop.
No more Mister Nice Guy... >: |
-
I have a loop in my razor view as below
@foreach(var inmate in Model) { @inmate.inmateid @inmate.inmateid }
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
why don't you try to do this??: @foreach(var inmate in Model) { @inmate.inmateid }
-
Because you enumerating collection, and for each item You are writing this item twice. If you want it just once remove one @inmate.inmateid from inside foreach loop.
No more Mister Nice Guy... >: |
That really is a very silly mistake
-
That really is a very silly mistake
Yes it is. But is not mine. You should answer to the question not mine answer. Take care.
No more Mister Nice Guy... >: |