Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to target a public property of class T in a model Listvia asp-for ?

$
0
0

public class MyModelClass { public string propertyA { set; get; } public int propertyB { set; get; } }

My View uses a List<MyModelClass>  model to load a list of items for editing.

I am able to access the list of edited items through @Model[i].propertyA while iterating with i as the for loop indexer.

However I need to access the originally loaded items through the asp-for tag helper as follows:

<input type = "input" asp-for = "[@i].propertyA" />

This last line doesn't work. 

NOTE: when the model is not a List<MyModelClass> but just an instance of the MyModelClass, 

I simply use the following <input type = "input" asp-for = "propertyA" /> 

and it works without an issue.

so, how does one use asp-for to target a property of a class T when the Model is List<T> 


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>