Exemplo n.º 1
0
        private static string TextAreaBuilder(HtmlControlHelper helper,
                                              string name, string value, int rows, int columns,
                                              IDictionary <string, object> attributes)
        {
            if (attributes == null)
            {
                attributes = new ValueDictionary();
            }

            HtmlElementBuilder htb = new HtmlElementBuilder("textarea");

            htb.Attributes.Merge(attributes, true);
            htb.Attributes.Merge("name", name, true);
            htb.Attributes.Merge("rows", rows, false);
            htb.Attributes.Merge("cols", columns, false);
            htb.InnerText = value ?? String.Empty;

            return(htb.ToString());
        }
Exemplo n.º 2
0
 public static string RadioButton(this HtmlControlHelper helper,
                                  string name, object value)
 {
     return(RadioButton(helper, name, value, new ValueDictionary()));
 }
Exemplo n.º 3
0
 public static string ListBox(this HtmlControlHelper helper,
                              string name, MultiSelectList list, object attributes)
 {
     return(ListBox(helper, name, list, new ValueDictionary(attributes)));
 }
Exemplo n.º 4
0
 public static string ListBox(this HtmlControlHelper helper,
                              string name, IEnumerable list, string dataTextField,
                              IDictionary <string, object> attributes)
 {
     return(ListBox(helper, name, list, dataTextField, null, null, attributes));
 }
Exemplo n.º 5
0
 public static string ListBox(this HtmlControlHelper helper,
                              string name, IEnumerable list)
 {
     return(ListBox(helper, name, list,
                    null, null, null, null));
 }
Exemplo n.º 6
0
 public static string DropDownList(this HtmlControlHelper helper,
                                   string name, SelectList list)
 {
     return(SelectBuilder(helper, name, list, false, null));
 }
Exemplo n.º 7
0
 public static string DropDownList(this HtmlControlHelper helper,
                                   string name, IEnumerable list)
 {
     return(DropDownList(helper, name, list, null, null, null, null));
 }
Exemplo n.º 8
0
 public static string TextArea <TModel>(this HtmlControlHelper <TModel> helper,
                                        string name, Expression <Func <TModel, string> > value)
     where TModel : class
 {
     return(TextArea(helper, name, value, 2, 20, null));
 }
Exemplo n.º 9
0
 public static string Password(this HtmlControlHelper helper, string name)
 {
     return(Password(helper, name, null, new ValueDictionary()));
 }
Exemplo n.º 10
0
 public static string TextBox(this HtmlControlHelper helper,
                              string name, object value)
 {
     return(TextBox(helper, name, value, new ValueDictionary()));
 }
Exemplo n.º 11
0
 public static string Hidden(this HtmlControlHelper helper,
                             string name, IDictionary <string, object> attributes)
 {
     return(Hidden(helper, name, null, attributes));
 }
Exemplo n.º 12
0
 public static string RadioButton <TModel>(this HtmlControlHelper <TModel> helper,
                                           string name, object value, Expression <Func <TModel, bool> > isChecked)
     where TModel : class
 {
     return(RadioButton(helper, name, value, isChecked, null));
 }
Exemplo n.º 13
0
 public static string RadioButton(this HtmlControlHelper helper,
                                  string name, object value, bool isChecked, object attributes)
 {
     return(RadioButton(helper, name, value, isChecked, new ValueDictionary(attributes)));
 }
Exemplo n.º 14
0
 public static string RadioButton(this HtmlControlHelper helper,
                                  string name, object value, IDictionary <string, object> attributes)
 {
     return(RadioButton(helper, name, value, false, attributes));
 }
Exemplo n.º 15
0
 public static string TextArea(this HtmlControlHelper helper,
                               string name, string value, int rows, int columns, object attributes)
 {
     return(TextArea(helper, name, value, rows, columns, new ValueDictionary(attributes)));
 }
Exemplo n.º 16
0
 public static string Password(this HtmlControlHelper helper,
                               string name, object value, object attributes)
 {
     return(Password(helper, name, value, new ValueDictionary(attributes)));
 }
Exemplo n.º 17
0
        private static string SelectBuilder(HtmlControlHelper helper,
                                            string name, MultiSelectList dataSource, bool isMultiple,
                                            IDictionary <string, object> attributes)
        {
            Precondition.Defined(name, () => Error.ArgumentNull("name"));

            if (attributes == null)
            {
                attributes = new ValueDictionary();
            }

            if (isMultiple)
            {
                attributes["multiple"] = "multiple";
            }
            else
            {
                attributes.Remove("multiple");
            }

            HtmlElementBuilder outer = new HtmlElementBuilder("select");

            outer.Attributes.Merge(attributes, true);
            outer.Attributes.Merge("name", name, true);

            if (dataSource != null)
            {
                StringBuilder builder = new StringBuilder();

                IEnumerable <ListItem> listItems = dataSource.GetListItems();
                string[] selectedValues          = null;

                if (helper.DataSource.Keys.Any(k => k.Equals(name, StringComparison.OrdinalIgnoreCase)))
                {
                    selectedValues = helper.DataSource.GetValue <string>(name, String.Empty)
                                     .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                }

                builder.AppendLine();

                foreach (ListItem item in listItems)
                {
                    if (selectedValues != null)
                    {
                        item.Selected = selectedValues.Any(s =>
                                                           String.Equals(item.Value, s, StringComparison.OrdinalIgnoreCase));
                    }

                    HtmlElementBuilder inner = new HtmlElementBuilder("option");
                    inner.InnerText = item.Text;

                    if (item.Value != null)
                    {
                        inner.Attributes.Merge("value", item.Value, true);
                    }

                    if (item.Selected)
                    {
                        inner.Attributes.Merge("selected", "selected");
                    }

                    builder.AppendLine(inner.ToString());
                }
                outer.InnerHtml = builder.ToString();
            }
            return(outer.ToString());
        }
Exemplo n.º 18
0
 public static string Password(this HtmlControlHelper helper,
                               string name, object value, IDictionary <string, object> attributes)
 {
     Precondition.Defined(name, () => Error.ArgumentNull("name"));
     return(InputBuilder(helper, "password", name, value, attributes));
 }
Exemplo n.º 19
0
 public static string TextArea <TModel>(this HtmlControlHelper <TModel> helper,
                                        string name, Expression <Func <TModel, string> > value, object attributes)
     where TModel : class
 {
     return(TextArea(helper, name, value, 2, 20, new ValueDictionary(attributes)));
 }
Exemplo n.º 20
0
 public static string Password <TModel>(this HtmlControlHelper <TModel> helper,
                                        string name, Expression <Func <TModel, object> > value)
     where TModel : class
 {
     return(Password(helper, name, value, null));
 }
Exemplo n.º 21
0
 public static string DropDownList(this HtmlControlHelper helper,
                                   string name, IEnumerable list, IDictionary <string, object> attributes)
 {
     return(DropDownList(helper, name, list, null, null, null, attributes));
 }
Exemplo n.º 22
0
 public static string Password <TModel>(this HtmlControlHelper <TModel> helper,
                                        string name, Expression <Func <TModel, object> > value, object attributes)
     where TModel : class
 {
     return(Password(helper, name, value, new ValueDictionary(attributes)));
 }
Exemplo n.º 23
0
 public static string DropDownList(this HtmlControlHelper helper,
                                   string name, SelectList list, IDictionary <string, object> attributes)
 {
     return(SelectBuilder(helper, name, list, false, attributes));
 }
Exemplo n.º 24
0
 public static string TextArea(this HtmlControlHelper helper,
                               string name, object attributes)
 {
     return(TextArea(helper, name, null, 2, 20, new ValueDictionary(attributes)));
 }
Exemplo n.º 25
0
 public static string ListBox(this HtmlControlHelper helper,
                              string name, IEnumerable list, object attributes)
 {
     return(ListBox(helper, name, list,
                    null, null, null, new ValueDictionary(attributes)));
 }
Exemplo n.º 26
0
 public static string TextArea(this HtmlControlHelper helper,
                               string name, string value)
 {
     return(TextArea(helper, name, value, 2, 20, new ValueDictionary()));
 }
Exemplo n.º 27
0
 public static string ListBox(this HtmlControlHelper helper,
                              string name, MultiSelectList list)
 {
     return(ListBox(helper, name, list, null));
 }
Exemplo n.º 28
0
 public static string TextArea(this HtmlControlHelper helper,
                               string name, string value, IDictionary <string, object> attributes)
 {
     return(TextArea(helper, name, value, 2, 20, attributes));
 }
Exemplo n.º 29
0
 public static string ListBox(this HtmlControlHelper helper,
                              string name, MultiSelectList list, IDictionary <string, object> attributes)
 {
     return(SelectBuilder(helper, name, list, true, attributes));
 }
Exemplo n.º 30
0
 public static string CheckBox(this HtmlControlHelper helper,
                               string name, object value, IDictionary <string, object> attributes)
 {
     Precondition.Defined(name, () => Error.ArgumentNull("name"));
     return(CheckBox(helper, name, value, false, attributes));
 }