1 Replies - 525 Views - Last Post: 14 February 2019 - 09:58 PM Rate Topic: -----

#1 ahmedba   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 24-January 14

Cannot apply index with [ ] to an expression of type icollection MVC v

Posted 14 February 2019 - 06:38 PM

problem
cannot apply index with [ ] to an expression of type Icollection mvc view asp.net core 2.1

Code:
public class SalesHeader
    {
        public SalesHeader()
        {

        }
        public int SalesYear { get; set; }
        public int BranchCode { get; set; }
        public ICollection<SalesFooter> SalesFooters { get; set; }
    }


What I have tried:

Code:
@for (var i = 0; i < Model.SalesFooters.Count; ++i)
                   {
                       <tr>
                           <td>
                               @Html.EditorFor(f => f.SalesFooters[i].ItemCode)
                           </td>
                           <td>
                               @Html.EditorFor(f => f.SalesFooters[i].Quantity)
                           </td>
                           <td>
                               @Html.EditorFor(f => f.SalesFooters[i].UnitPrice)
                           </td>
                       </tr>
                   }


it show my in for loop above compile error

cannot apply index with [ ] to an expression of type Icollection mvc view asp.net core 2.1

Place Of ERROR

the error show on view Edit under f.salesfooter[i] on for loop because indexing is applied to list

and i use collection

my question

How to convert collection to list ?

OR

How using indexing in collection ?

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot apply index with [ ] to an expression of type icollection MVC v

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15061
  • View blog
  • Posts: 60,146
  • Joined: 12-June 08

Re: Cannot apply index with [ ] to an expression of type icollection MVC v

Posted 14 February 2019 - 09:58 PM

Have you considered using a 'for each'?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1