/// <summary> /// Displays the name for. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <param name="html">The HTML.</param> /// <param name="propertyInfo">The property information.</param> /// <returns></returns> public static HtmlString DisplayNameFor <TModel>(HtmlHelper <TModel> html, PropertyInfo propertyInfo) { var lambda = DynamicExpression.ParseLambda(typeof(TModel), propertyInfo.PropertyType, "m => m." + propertyInfo.Name, null); var methods = GetMethods(typeof(DisplayNameExtensions), "DisplayNameFor", "TValue"); var method = methods.Where(x => { var parms = x.GetParameters(); return(parms.Length == 2); }).First(); if (method == null) { return(new HtmlString(string.Empty)); } method = method.MakeGenericMethod(typeof(TModel), lambda.Body.Type); var htmlString = method.Invoke(null, new object[] { html, lambda }).ToString(); return(new HtmlString(HttpUtility.HtmlDecode(htmlString))); }
/// <summary> /// Drops down group list for. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <param name="html">The HTML.</param> /// <param name="propertyInfo">The property information.</param> /// <param name="selectList">The select list.</param> /// <param name="optionLabel">The option label.</param> /// <param name="htmlAttributes">The HTML attributes.</param> /// <returns></returns> public static HtmlString DropDownGroupListFor <TModel>(HtmlHelper <TModel> html, PropertyInfo propertyInfo, IEnumerable <GroupedSelectListItem> selectList, string optionLabel, RouteValueDictionary htmlAttributes) { var lambda = DynamicExpression.ParseLambda(typeof(TModel), propertyInfo.PropertyType, "m => m." + propertyInfo.Name, null); var methods = GetMethods(typeof(DropDownListExtensions), "DropDownGroupListFor", "TProperty"); var method = methods.Where(x => { var parms = x.GetParameters(); return(parms.Length == 5 && parms[2].ParameterType.Name == "IEnumerable`1" && parms[3].ParameterType.Name == "String" && parms[4].ParameterType.Name == "IDictionary`2"); }).First(); if (method == null) { return(new HtmlString(string.Empty)); } method = method.MakeGenericMethod(typeof(TModel), lambda.Body.Type); var htmlString = method.Invoke(null, new[] { html, lambda, selectList, optionLabel, (object)htmlAttributes }).ToString(); return(new HtmlString(HttpUtility.HtmlDecode(htmlString))); }
/// <summary> /// CheckBoxes for. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <param name="html">The HTML.</param> /// <param name="propertyInfo">The property information.</param> /// <param name="htmlAttributes">The HTML attributes.</param> /// <returns></returns> public static HtmlString CheckBoxFor <TModel>(HtmlHelper <TModel> html, PropertyInfo propertyInfo, RouteValueDictionary htmlAttributes) { var lambda = DynamicExpression.ParseLambda(typeof(TModel), propertyInfo.PropertyType, "m => m." + propertyInfo.Name, null); var methods = GetMethods(typeof(InputExtensions), "CheckBoxFor"); var method = methods.Where(x => { var parms = x.GetParameters(); return(parms.Length == 3 && parms[2].ParameterType.Name == "IDictionary`2"); }).FirstOrDefault(); if (method == null) { return(new HtmlString(string.Empty)); } method = method.MakeGenericMethod(typeof(TModel)); var htmlString = method.Invoke(null, new[] { html, lambda, (object)htmlAttributes }).ToString(); return(new HtmlString(HttpUtility.HtmlDecode(htmlString))); }