Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert lambda expression to type 'object' because it is not a delegate type with an 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 like:

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

When I access PatientId in my view with something like:

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

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

like image 436
Xaisoft Avatar asked Apr 26 '13 18:04

Xaisoft


1 Answers

DisplayForModel actually uses Display Templates to display your model and is normally called without parameters. If this is what you intended then you will have to make a new DisplayTemplate. For anyone interested, here is a nice tutorial by Phil Haack on Display Templates and DisplayForModel: http://haacked.com/archive/2010/05/05/asp-net-mvc-tabular-display-template.aspx.

However, if you just wanted to have a label for that field, then you should just use DisplayFor

@Html.DisplayFor(modelItem => modelItem.PatientId)
like image 95
Travis J Avatar answered Sep 30 '22 05:09

Travis J