Has anyone written or is there a way to invoke EditorFor using a property name instead of using an expression.
EditorFor("Code")
as opposed to
EditorFor(_ => _.Code)
I want to write something more generic. Invoking EditorFor by creating an expression is proving tiresome, and I cannot believe there is not a better way.
This doesn’t work.
var root = Expression.Parameter(Model.GetType(), "_");
var expr = Expression.Lambda(Expression.MakeMemberAccess(root, property), root);
var ef = (Expression<Func<Product, string>>) expr;
var method = typeof(EditorExtensions).GetMethod("EditorFor", BindingFlags.Public | BindingFlags.Static, null, new[] {typeof(HtmlHelper<>), typeof(Expression<Func<,>>)}, null);
method is always null, I have tried a lot of things.
Cheers
I think the
Editormethod is what you are after: http://msdn.microsoft.com/en-us/library/system.web.mvc.html.editorextensions.editor.aspx