Hey.
I'm trying to display an item that is in a list of the model, but everything i've tried doesn't seem to work.
<DataGridColumn TItem="Student" Field="@nameof(Student.Name.Text)" Caption="Name"></DataGridColumn>
Does not work. _Student.Name_ is a list and _Text_ is one of the items.
I've tried
Field=Name.Text
with no success.
Any suggestions?
When you use nameof(Student.Name.Text) it will get only the Text and then it will try to get that field name from Student object.
Try with Field="Student.Name.Text".
That doesn't work either.
I get this exception
_ArgumentException: 'Student' is not a member of type 'Student' (Parameter 'propertyOrFieldName')_
The model is structured like this:
public class HumanName
{
public string Text {get; set;};
}
public class Student
{
public List<HumanName> Name {get; set;};
}
if that helps
I think the issue here is that Name is a list, and there is no way of telling what item from the list you want.
If you want to keep it as a list, I would suggest using a custom DisplayTemplate.
Something like the following:
<DataGridNumericColumn TItem="Student" Field="@nameof(Student.Name)" Caption="Name">
<DisplayTemplate>
@context.Name.First().Text
</DisplayTemplate>
</DataGridNumericColumn>
But @stsrki might have a better suggestion!
That worked like a charm! Thank you!
Most helpful comment
I think the issue here is that
Nameis a list, and there is no way of telling what item from the list you want.If you want to keep it as a list, I would suggest using a custom
DisplayTemplate.Something like the following:
But @stsrki might have a better suggestion!