I'm trying to store a Func<T>
or Expression<Func<T>>
variable into a Html.HiddenFor(), inside a Razor view, in order to post it back to the controller, but it does not work as expected, as it's stored as a string, and comes back as null to the controller.
I need it to access particular properties of a model, and set them with other data passed to the controller at the same time.
I cannot find setter properties that I could store and use back in the controller to build the Func<object>
variable (like I would with any complex object).
For instance, I send to the view, a model, containing a list of these:
new DataConflict<AppointmentEditModel, dynamic, dynamic>(x => x.StartDate, null, Start, appointment.StartDate)
then I store the lambda expression x => x.StartDate
, which is a Expression<Func<T>>
, like this (it seems to store it as a string):
@Html.HiddenFor(m => m.Appointment.ConflictList[i].DataProperty)
And when it comes back to the controller after submission, all the lambda containing properties are null.
I expect the controller to receive back the lambda expression containing object, it sent to the view.
Thank you.