It is not possible to convert a lambda expression to type "object" because it is not a delegate type with int

I have a list of patients. One of the properties of the Patient class is PatientId, which is an int. My list is initialized as follows:

List<Patient> = new List<Patient>() { new Patient { PatientId = 1, 
                                                    FirstName = "Jane", 
                                                    LastName = "Doe"}};

When I access the PatientId in my view with something like:

@Html.DisplayForModel(modelItem => modelItem.PatientId) //Error

I get an error message: Cannot convert lambda expression to type 'object' because it is not a delegate type

+5
source share
2 answers

DisplayForModel Display Templates . , , DisplayTemplate. , , DisplayForModel: http://haacked.com/archive/2010/05/05/asp-net-mvc-tabular-display-template.aspx.

, , DisplayFor

@Html.DisplayFor(modelItem => modelItem.PatientId)
+5

@Html.DisplayFor() @Html.DisplayModelFor(). . @Html.DisplayFor(model => model.PatientId)

+3

All Articles