public static MvcHtmlString AppDropDownListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, List <ComboRow> options, object htmlAttributes) { var control = new RenderComboBox(); control.Options = options; ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); control.Name = metadata.PropertyName; control.ID = metadata.PropertyName; Object value = metadata.Model; if (value != null) { control.Selected = value; } 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>"); } var result = MvcHtmlString.Create(control.ToString()); return(result); }
public static MvcHtmlString AppDropDownList(this HtmlHelper htmlHelper, string name, List <ComboRow> options, object value, object htmlAttributes) { var control = new RenderComboBox(); control.Options = options; control.Name = name; control.ID = name; if (value != null) { control.Selected = 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())); }