asp.net mvc - How do I retrieve the VALUE of the object's property that is passed to my custom EditorFor from the view? -
system.web.mvc has htmlhelper contains method called editorfor renders editing control associated data type in view.
im trying create own editorfor method extending asp.net mvc 2 htmlhelper. have following:
public static string editorfornew<tmodel, tproperty>(this htmlhelper<tmodel> helper, expression<func<tmodel, tproperty>> item) { string value = ""; string name = item.tostring(); // corrected in comment answer below! type type = typeof(tproperty); if (type == typeof(int) || type == typeof(int?) || type == typeof(double) || type == typeof(double?) || type == typeof(decimal) || type == typeof(decimal?) || type == typeof(float) || type == typeof(float?)) { return helper.textbox(name, value, new { @class = "number" }).tostring(); } else { return helper.textbox(name, value).tostring(); } }
can explain how retrieve value of object's property passed view?
you need use modelmetadata:
modelmetadata metadata = modelmetadata.fromlambdaexpression(item, helper.viewdata);
you can value metadata.model
property.
Comments
Post a Comment