I want to create a dynamic controls generator in mvc 4, creating a controls in code using Extensions Methods like TextBoxFor(), but can pass in diamond syntax the type of my property for create a Expression. This is my function what create a Expression.
private static Expression<Func<IViewModel, TProperty>> createExpression<TProperty>(string propertyName)
{
ParameterExpression parameter = Expression.Parameter(myModel.GetType(), "item");
Expression<Func<IViewModel, TProperty>> lambda;
lambda = Expression.Lambda<Func<IViewModel, TProperty>>(Expression.PropertyOrField(parameter, propertyName), parameter);
return lambda;
}
And my call
InputExtensions.TextBoxFor(myhelper,createExpression<property.PropertyType>(property.Name);
in diamond syntax I have an error, just I want to pass a type of my property.
Aucun commentaire:
Enregistrer un commentaire