C#C
C#2y ago
iookei

Sub-expression cannot be used in an argument to nameof.

Working with a ASP.Net Core webapp using NET7
I have a model
c#
public class TblStudent 
{
    [Display(Name = "ID")]
    public string? StuID { get; set; }

    [Display(Name = "Full Name")]
    public string? StuFullName { get; set; }
}


I also have a ViewModel
c#
public class StudentIndexViewModel
{
    public IEnumerable<TblStudent> StuTable { get; set; } = new List<TblStudent>();
{


in my View I'm trying to get the property name from TblStudent using this
c#
@(nameof(Model.StuTable.FirstOrDefault().StuFullName))


however, I'm having Sub-expression cannot be used in an argument to nameof. error

Anyone know how to display just the property name?
Was this page helpful?