AddAttributes() public méthode

public AddAttributes ( object attributes ) : void
attributes object
Résultat void
        public static HtmlString CheckBox(this HtmlHelper This, string key, object value = null, object htmlAttributes = null)
        {
            This.RegisterFormField(key);

            var tag = new TagBuilder("input");

            tag.AddAttribute("type", "checkbox");
            tag.AddAttribute("name", key);
            tag.AddAttribute("id", key);
            tag.AddAttribute("value", "true");
            tag.AddAttributes(htmlAttributes);

            if ((bool)Convert.ChangeType(This.ResolveFormValue(key, value), typeof(bool)))
            {
                tag.AddAttribute("checked", "checked");
            }

            if (!This.Context.ModelState.IsFieldValid(key))
                tag.AddClass("model_validation_error");

            return new HtmlString(tag.Render());
        }
        public static HtmlString Input(this HtmlHelper This, string type, string key, object value = null, object htmlAttributes = null)
        {
            This.RegisterFormField(key);

            var tag = new TagBuilder("input");

            tag.AddAttribute("type", type);
            tag.AddAttribute("name", key);
            tag.AddAttribute("id", key);
            if (type != "password")
                tag.AddAttribute("value", This.ResolveFormValue(key, value));
            tag.AddAttributes(htmlAttributes);

            if (!This.Context.ModelState.IsFieldValid(key))
                tag.AddClass("model_validation_error");

            return new HtmlString(tag.Render());
        }
        public static HtmlString TextArea(this HtmlHelper This, string key, object value = null, object htmlAttributes = null)
        {
            This.RegisterFormField(key);

            var tag = new TagBuilder("textarea");

            tag.AddAttribute("name", key);
            tag.AddAttribute("id", key);
            tag.AddAttribute("cols", 40);
            tag.AddAttribute("rows", 4);

            tag.AddAttributes(htmlAttributes);
            if (!This.Context.ModelState.IsFieldValid(key))
                tag.AddClass("model_validation_error");

            var text = This.ResolveFormValue(key, value);
            if (text != null)
                tag.AddContent(text.ToString());

            tag.AlwaysUseFullForm = true;

            return new HtmlString(tag.Render());
        }
        public static HtmlString RadioButton(this HtmlHelper This, string key, object button_value, object form_value = null, object htmlAttributes = null)
        {
            var fd = This.GetFormData();

            if (fd.RadioButtonIndicies==null)
            {
                fd.RadioButtonIndicies = new Dictionary<string, int>();
            }

            int index;
            if (!fd.RadioButtonIndicies.TryGetValue(key, out index))
            {
                index = 0;
            }
            index++;
            fd.RadioButtonIndicies[key] = index;
            string id = key + index.ToString();

            This.RegisterFormField(key);

            form_value = This.ResolveFormValue(key, form_value);

            fd.LastFormField = id;

            var tag = new TagBuilder("input");

            tag.AddAttribute("type", "radio");
            tag.AddAttribute("name", key);
            tag.AddAttribute("id", id);
            tag.AddAttribute("value", button_value);
            tag.AddAttributes(htmlAttributes);

            if (button_value.Equals(form_value))
            {
                tag.AddAttribute("checked", "checked");
            }

            if (!This.Context.ModelState.IsFieldValid(key))
                tag.AddClass("model_validation_error");

            return new HtmlString(tag.Render());
        }