Пример #1
0
        public static MvcHtmlString RadioButton(this LayuiHelper htmlHelper, string name, object value, IDictionary <string, object> htmlAttributes)
        {
            // Determine whether or not to render the checked attribute based on the contents of ViewData.
            string valueString = Convert.ToString(value, CultureInfo.CurrentCulture);
            bool   isChecked   = (!String.IsNullOrEmpty(name)) && (String.Equals(htmlHelper.EvalString(name), valueString, StringComparison.OrdinalIgnoreCase));
            // checked attributes is implicit, so we need to ensure that the dictionary takes precedence.
            RouteValueDictionary attributes = ToRouteValueDictionary(htmlAttributes);

            if (attributes.ContainsKey("checked"))
            {
                return(InputHelper(htmlHelper,
                                   InputType.Radio,
                                   metadata: null,
                                   name: name,
                                   value: value,
                                   useViewData: false,
                                   isChecked: false,
                                   setId: true,
                                   isExplicitValue: true,
                                   format: null,
                                   htmlAttributes: attributes));
            }

            return(RadioButton(htmlHelper, name, value, isChecked, htmlAttributes));
        }
Пример #2
0
        private static MvcHtmlString HiddenHelper(LayuiHelper htmlHelper, ModelMetadata metadata, object value, bool useViewData, string expression, IDictionary <string, object> htmlAttributes)
        {
            Binary binaryValue = value as Binary;

            if (binaryValue != null)
            {
                value = binaryValue.ToArray();
            }

            byte[] byteArrayValue = value as byte[];
            if (byteArrayValue != null)
            {
                value = Convert.ToBase64String(byteArrayValue);
            }

            return(InputHelper(htmlHelper,
                               InputType.Hidden,
                               metadata,
                               expression,
                               value,
                               useViewData,
                               isChecked: false,
                               setId: true,
                               isExplicitValue: true,
                               format: null,
                               htmlAttributes: htmlAttributes));
        }
Пример #3
0
        private static MvcHtmlString RadioButtonHelper(LayuiHelper htmlHelper, ModelMetadata metadata, object model, string name, object value, bool?isChecked, IDictionary <string, object> htmlAttributes)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            RouteValueDictionary attributes = ToRouteValueDictionary(htmlAttributes);

            bool explicitValue = isChecked.HasValue;

            if (explicitValue)
            {
                attributes.Remove("checked"); // Explicit value must override dictionary
            }
            else
            {
                string valueString = Convert.ToString(value, CultureInfo.CurrentCulture);
                isChecked = model != null &&
                            !String.IsNullOrEmpty(name) &&
                            String.Equals(model.ToString(), valueString, StringComparison.OrdinalIgnoreCase);
            }

            return(InputHelper(htmlHelper,
                               InputType.Radio,
                               metadata,
                               name,
                               value,
                               useViewData: false,
                               isChecked: isChecked ?? false,
                               setId: true,
                               isExplicitValue: true,
                               format: null,
                               htmlAttributes: attributes));
        }
Пример #4
0
 public static MvcHtmlString Hidden(this LayuiHelper htmlHelper, string name, object value, IDictionary <string, object> htmlAttributes)
 {
     return(HiddenHelper(htmlHelper,
                         metadata: null,
                         value: value,
                         useViewData: value == null,
                         expression: name,
                         htmlAttributes: htmlAttributes));
 }
Пример #5
0
        public static MvcHtmlString HiddenFor <TModel, TProperty>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, IDictionary <string, object> htmlAttributes)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);

            return(HiddenHelper(htmlHelper,
                                metadata,
                                metadata.Model,
                                false,
                                ExpressionHelper.GetExpressionText(expression),
                                htmlAttributes));
        }
Пример #6
0
        public static MvcHtmlString RadioButtonFor <TModel, TProperty>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, object value, IDictionary <string, object> htmlAttributes)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);

            return(RadioButtonHelper(htmlHelper,
                                     metadata,
                                     metadata.Model,
                                     ExpressionHelper.GetExpressionText(expression),
                                     value,
                                     null /* isChecked */,
                                     htmlAttributes));
        }
Пример #7
0
        public static MvcHtmlString PasswordFor <TModel, TProperty>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, IDictionary <string, object> htmlAttributes)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            return(PasswordHelper(htmlHelper,
                                  ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData),
                                  ExpressionHelper.GetExpressionText(expression),
                                  value: null,
                                  htmlAttributes: htmlAttributes));
        }
Пример #8
0
 private static MvcHtmlString PasswordHelper(LayuiHelper htmlHelper, ModelMetadata metadata, string name, object value, IDictionary <string, object> htmlAttributes)
 {
     return(InputHelper(htmlHelper,
                        InputType.Password,
                        metadata,
                        name,
                        value,
                        useViewData: false,
                        isChecked: false,
                        setId: true,
                        isExplicitValue: true,
                        format: null,
                        htmlAttributes: htmlAttributes));
 }
Пример #9
0
        public static MvcHtmlString CheckBoxFor <TModel>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, bool> > expression, IDictionary <string, object> htmlAttributes)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            ModelMetadata metadata  = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
            bool?         isChecked = null;

            if (metadata.Model != null)
            {
                bool modelChecked;
                if (Boolean.TryParse(metadata.Model.ToString(), out modelChecked))
                {
                    isChecked = modelChecked;
                }
            }

            return(CheckBoxHelper(htmlHelper, metadata, ExpressionHelper.GetExpressionText(expression), isChecked, htmlAttributes));
        }
Пример #10
0
        public static MvcHtmlString RadioButton(this LayuiHelper htmlHelper, string name, object value, bool isChecked, IDictionary <string, object> htmlAttributes)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            // checked attribute is an explicit parameter so it takes precedence.
            RouteValueDictionary attributes = ToRouteValueDictionary(htmlAttributes);

            attributes.Remove("checked");
            return(InputHelper(htmlHelper,
                               InputType.Radio,
                               metadata: null,
                               name: name,
                               value: value,
                               useViewData: false,
                               isChecked: isChecked,
                               setId: true,
                               isExplicitValue: true,
                               format: null,
                               htmlAttributes: attributes));
        }
Пример #11
0
        private static MvcHtmlString CheckBoxHelper(LayuiHelper htmlHelper, ModelMetadata metadata, string name, bool?isChecked, IDictionary <string, object> htmlAttributes)
        {
            RouteValueDictionary attributes = ToRouteValueDictionary(htmlAttributes);

            bool explicitValue = isChecked.HasValue;

            if (explicitValue)
            {
                attributes.Remove("checked"); // Explicit value must override dictionary
            }

            return(InputHelper(htmlHelper,
                               InputType.CheckBox,
                               metadata,
                               name,
                               value: "true",
                               useViewData: !explicitValue,
                               isChecked: isChecked ?? false,
                               setId: true,
                               isExplicitValue: false,
                               format: null,
                               htmlAttributes: attributes));
        }
Пример #12
0
 public static MvcHtmlString TextBoxFor <TModel, TProperty>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, IDictionary <string, object> htmlAttributes)
 {
     return(htmlHelper.TextBoxFor(expression, format: null, htmlAttributes: htmlAttributes));
 }
Пример #13
0
        public static MvcHtmlString TextBoxFor <TModel, TProperty>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, string format, IDictionary <string, object> htmlAttributes)
        {
            HtmlHelper <TModel> html = new HtmlHelper <TModel>(htmlHelper.ViewContext, htmlHelper.ViewDataContainer, htmlHelper.RouteCollection);

            return(html.TextBoxFor <TModel, TProperty>(expression, format, htmlAttributes));
        }
Пример #14
0
 public static MvcHtmlString TextBoxFor <TModel, TProperty>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, string format, object htmlAttributes)
 {
     return(htmlHelper.TextBoxFor(expression, format: format, htmlAttributes: LayuiHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
 }
Пример #15
0
 public static MvcHtmlString CheckBox(this LayuiHelper htmlHelper, string name, bool isChecked, IDictionary <string, object> htmlAttributes)
 {
     return(CheckBoxHelper(htmlHelper, metadata: null, name: name, isChecked: isChecked, htmlAttributes: htmlAttributes));
 }
Пример #16
0
 public static MvcHtmlString RadioButtonFor <TModel, TProperty>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, object value, object htmlAttributes)
 {
     return(RadioButtonFor(htmlHelper, expression, value, LayuiHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
 }
Пример #17
0
 public static MvcHtmlString TextBoxFor <TModel, TProperty>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, string format)
 {
     return(htmlHelper.TextBoxFor(expression, format, (IDictionary <string, object>)null));
 }
Пример #18
0
        public static MvcHtmlString TextBox(this LayuiHelper htmlHelper, string name, object value, string format, object htmlAttributes)
        {
            HtmlHelper html = new HtmlHelper(htmlHelper.ViewContext, htmlHelper.ViewDataContainer, htmlHelper.RouteCollection);

            return(html.TextBox(name, value, format, htmlAttributes));
        }
Пример #19
0
 public static MvcHtmlString CheckBox(this LayuiHelper htmlHelper, string name, bool isChecked)
 {
     return(CheckBox(htmlHelper, name, isChecked, htmlAttributes: (object)null));
 }
Пример #20
0
 public static MvcHtmlString TextBox(this LayuiHelper htmlHelper, string name, object value)
 {
     return(TextBox(htmlHelper, name, value, format: null));
 }
Пример #21
0
 public static MvcHtmlString PasswordFor <TModel, TProperty>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, object htmlAttributes)
 {
     return(PasswordFor(htmlHelper, expression, LayuiHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
 }
Пример #22
0
 public static MvcHtmlString RadioButton(this LayuiHelper htmlHelper, string name, object value, bool isChecked)
 {
     return(RadioButton(htmlHelper, name, value, isChecked, htmlAttributes: (object)null));
 }
Пример #23
0
 public static MvcHtmlString CheckBox(this LayuiHelper htmlHelper, string name, object htmlAttributes)
 {
     return(CheckBox(htmlHelper, name, LayuiHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
 }
Пример #24
0
 public static MvcHtmlString RadioButton(this LayuiHelper htmlHelper, string name, object value, bool isChecked, object htmlAttributes)
 {
     return(RadioButton(htmlHelper, name, value, isChecked, LayuiHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
 }
Пример #25
0
 public static MvcHtmlString CheckBoxFor <TModel>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, bool> > expression)
 {
     return(CheckBoxFor(htmlHelper, expression, htmlAttributes: null));
 }
Пример #26
0
 public static MvcHtmlString TextBox(this LayuiHelper htmlHelper, string name, object value, IDictionary <string, object> htmlAttributes)
 {
     return(TextBox(htmlHelper, name, value, format: null, htmlAttributes: htmlAttributes));
 }
Пример #27
0
 public static MvcHtmlString CheckBoxFor <TModel>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, bool> > expression, object htmlAttributes)
 {
     return(CheckBoxFor(htmlHelper, expression, LayuiHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
 }
Пример #28
0
 public static MvcHtmlString TextBoxFor <TModel, TProperty>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression)
 {
     return(htmlHelper.TextBoxFor(expression, format: null));
 }
Пример #29
0
 public static MvcHtmlString TextBox(this LayuiHelper htmlHelper, string name, object value, string format)
 {
     return(TextBox(htmlHelper, name, value, format, htmlAttributes: (object)null));
 }
Пример #30
0
 public static MvcHtmlString RadioButtonFor <TModel, TProperty>(this LayuiHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, object value)
 {
     return(RadioButtonFor(htmlHelper, expression, value, htmlAttributes: null));
 }