public IEncodedString DisplayNameFor <TValue>(Expression <Func <TModel, TValue> > expression) { var resolvedLabelText = UtilHelper.GetPropertyDisplayName(expression); if (String.IsNullOrEmpty(resolvedLabelText)) { return(new HtmlEncodedString(string.Empty)); } return(new HtmlEncodedString(resolvedLabelText)); }
public IEncodedString LabelFor <TValue>(Expression <Func <TModel, TValue> > expression, object htmlAttributes = null, string labelText = null) { var resolvedLabelText = labelText ?? UtilHelper.GetPropertyDisplayName(expression); var propName = UtilHelper.GetPropertyName(expression); var htmlAttributesStr = string.Empty; if (String.IsNullOrEmpty(resolvedLabelText)) { return(new HtmlEncodedString(string.Empty)); } if (htmlAttributes != null) { var htmlAttributesDict = UtilHelper.ObjectToDictionary(htmlAttributes); htmlAttributesStr = UtilHelper.ConvertDictionaryToString(htmlAttributesDict); } var tag = string.Format("<label {2}for=\"{0}\">{1}</label>", propName, HttpUtility.HtmlEncode(resolvedLabelText), htmlAttributesStr); return(new RawString(tag)); }