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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With