I need to create Expression<Func<TModel, TValue>> from my model.
How to access the property in the model:
ViewModel.CustomFieldCollection[1].PrimaryFields[3].Value
where 1 & 3 are the indexes which will updated at runtime.
I am trying to creating an expression, to be passed to a HtmlHelper, to generate an HtmlString for me.
var viewModelExpParam = Expression.Parameter(typeof(ViewModel));
var fieldParam = Expression.Property(viewModelExpParam, "CustomFieldCollection[1]");
var expression = Expression.Lambda<Func<TModel, TValue>>(fieldParam, viewModelExpParam);
But the above code gives the error while creating fieldParam, as it is not the object but a collection object.
Can i generate an expression to access ViewModel.CustomFieldCollection[1].PrimaryFields[3].Value in HtmlHelper at runtime?