/// <summary> /// Renders list editor for given property. /// Editor template for corresponding generic list type should be located in Shared/ListEditors/_{TypeName}ListEditor.cshtml. /// </summary> public static IHtmlContent ListEditorFor <TModel, TResult> (this IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TResult> > expression, string label = null) where TResult : IList { var model = htmlHelper.ViewData.Model; var listObject = expression.Compile().DynamicInvoke(model); var viewDataDictionary = new ViewDataDictionary(htmlHelper.ViewData); viewDataDictionary.InjectModelId(model); viewDataDictionary.ChainPropertyPath(expression); viewDataDictionary["Label"] = label ?? ExtractPropertyName(expression); return(htmlHelper.Partial("ListEditors/_ListEditorPartial", listObject, viewDataDictionary)); }
/// <summary> /// Renders value editor for given property of custom type. /// Corresponding editor template should be located in Shared/TypeEditors/_{TypeName}TypeEditor.cshtml. /// </summary> public static IHtmlContent TypeEditorFor <TModel, TResult> (this IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TResult> > expression, string label = null) { var model = htmlHelper.ViewData.Model; var editedObject = expression.Compile().DynamicInvoke(model); var typeName = editedObject?.GetType().Name ?? "Null"; var viewDataDictionary = new ViewDataDictionary(htmlHelper.ViewData); viewDataDictionary.InjectModelId(model); viewDataDictionary.ChainPropertyPath(expression); viewDataDictionary["Label"] = label ?? ExtractPropertyName(expression); return(htmlHelper.Partial($"TypeEditors/_{typeName}TypeEditor", editedObject, viewDataDictionary)); }