示例#1
0
 private static void HtmlAttributes(AppControl control, object htmlAttributes)
 {
     if (htmlAttributes != null)
     {
         var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
         foreach (var attr in attributes)
         {
             try
             {
                 if (attr.Value != null && attr.Key != null)
                 {
                     if (attr.Key.ToLower() == "id")
                     {
                         control.ID = attr.Value.ToString();
                     }
                     else if (attr.Key.ToLower() == "name")
                     {
                         control.Name = attr.Value.ToString();
                     }
                     else if (attr.Key.ToLower() == "readonly")
                     {
                         control.Readonly = (bool)attr.Value;
                     }
                     else if (attr.Key.ToLower() == "disabled")
                     {
                         control.Disabled = (bool)attr.Value;
                     }
                     else if (attr.Key.ToLower() == "text")
                     {
                         control.Text = attr.Value.ToString();
                     }
                     else if (attr.Key.ToLower() == "rows")
                     {
                         control.Rows = attr.Value.ToString();
                     }
                     else if (attr.Key.ToLower() == "style")
                     {
                         control.Style = attr.Value.ToString();
                     }
                     else if (attr.Key.ToLower() == "icon")
                     {
                         control.Icon = attr.Value.ToString();
                     }
                     else if (attr.Key.ToLower() == "checked")
                     {
                         if (attr.Value != null && (bool)attr.Value == true)
                         {
                             control.Attributes.Add("checked", attr.Value.ToString());
                         }
                     }
                     else if (attr.Key.ToLower() == "value")
                     {
                         control.Value = attr.Value.ToString();
                     }
                     else
                     {
                         control.Attributes.Add(attr.Key.Replace("_", "-").ToString(), attr.Value.ToString());
                     }
                 }
             }
             catch
             {
             }
         }
     }
 }
示例#2
0
        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()));
        }