iookei
iookei
CC#
Created by iookei on 4/22/2024 in #help
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; }
}
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>();
{
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))
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?
5 replies