Marcus Ruas
Marcus Ruas

Reputation: 45

Why can't i use foreach to fill an asp-for?

So, i want to generate inputs for each field of an object in an IEnumerable.

@foreach(var item in Model.RandomTable){
   <tr>
      <td><input asp-for="item.Parameter"/></td>
   </tr>
}

this Model is a ViewModel, this is the code from the ViewModel:

public class ViewModel{
   public IEnumerable<RandomClass> RandomTable{ get; set; }
}

the hypotetical Parameter i am trying to access is a primitive type, but when i try to build this, the following error occurs:

error CS1061: 'ViewModel' does not contain a definition for "item" and it wasn't possible to find any method with extension "item" that accepts the first argument of type 'ViewModel'

I altered the original names of the components, but the essentials are here, any suggestions of waht it might be?

Upvotes: 0

Views: 195

Answers (1)

Marcus Ruas
Marcus Ruas

Reputation: 45

ok, i found an answer, it's just put an @ before the item, worked just fine.

Upvotes: 1

Related Questions