private static MvcHtmlString AppTextFor <TModel, TProperty>(HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, AppControl control, int colspan, object htmlAttributes) { ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); Object value = metadata.Model; control.Name = metadata.PropertyName; if (!string.IsNullOrEmpty(metadata.DisplayName)) { control.Placeholder = metadata.DisplayName; } else { control.Placeholder = metadata.PropertyName.Replace("_", " "); } control.ID = metadata.PropertyName; control.ColSpan = colspan; if (value != null) { control.Value = value; control.Text = value.ToString(); } HtmlAttributes(control, htmlAttributes); ModelError modelError = htmlHelper.ViewData.ModelState.Where(w => w.Key == metadata.PropertyName).SelectMany(m => m.Value.Errors).FirstOrDefault(); if (modelError != null) { control.HtmlValidateString = MvcHtmlString.Create("<span class='validation_wrapper customValidation'><span>" + modelError.ErrorMessage + "</span></span>"); } return(MvcHtmlString.Create(control.ToString())); }
private static MvcHtmlString AppText(this HtmlHelper htmlHelper, AppControl control, string name, object value, object htmlAttributes) { control.Name = name; control.ID = name; control.Placeholder = name; control.Value = value; HtmlAttributes(control, htmlAttributes); ModelError modelError = htmlHelper.ViewData.ModelState.Where(w => w.Key == name).SelectMany(m => m.Value.Errors).FirstOrDefault(); if (modelError != null) { control.HtmlValidateString = MvcHtmlString.Create("<span class='validation_wrapper customValidation'><span>" + modelError.ErrorMessage + "</span></span>"); } return(MvcHtmlString.Create(control.ToString())); }