예제 #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());
        }
예제 #2
0
 public static string RadioButton(this HtmlControlHelper helper,
                                  string name, object value)
 {
     return(RadioButton(helper, name, value, new ValueDictionary()));
 }
예제 #3
0
 public static string ListBox(this HtmlControlHelper helper,
                              string name, MultiSelectList list, object attributes)
 {
     return(ListBox(helper, name, list, new ValueDictionary(attributes)));
 }
예제 #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));
 }
예제 #5
0
 public static string ListBox(this HtmlControlHelper helper,
                              string name, IEnumerable list)
 {
     return(ListBox(helper, name, list,
                    null, null, null, null));
 }
예제 #6
0
 public static string DropDownList(this HtmlControlHelper helper,
                                   string name, SelectList list)
 {
     return(SelectBuilder(helper, name, list, false, null));
 }
예제 #7
0
 public static string DropDownList(this HtmlControlHelper helper,
                                   string name, IEnumerable list)
 {
     return(DropDownList(helper, name, list, null, null, null, null));
 }
예제 #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));
 }
예제 #9
0
 public static string Password(this HtmlControlHelper helper, string name)
 {
     return(Password(helper, name, null, new ValueDictionary()));
 }
예제 #10
0
 public static string TextBox(this HtmlControlHelper helper,
                              string name, object value)
 {
     return(TextBox(helper, name, value, new ValueDictionary()));
 }
예제 #11
0
 public static string Hidden(this HtmlControlHelper helper,
                             string name, IDictionary <string, object> attributes)
 {
     return(Hidden(helper, name, null, attributes));
 }
예제 #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));
 }
예제 #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)));
 }
예제 #14
0
 public static string RadioButton(this HtmlControlHelper helper,
                                  string name, object value, IDictionary <string, object> attributes)
 {
     return(RadioButton(helper, name, value, false, attributes));
 }
예제 #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)));
 }
예제 #16
0
 public static string Password(this HtmlControlHelper helper,
                               string name, object value, object attributes)
 {
     return(Password(helper, name, value, new ValueDictionary(attributes)));
 }
예제 #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());
        }
예제 #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));
 }
예제 #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)));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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)));
 }
예제 #23
0
 public static string DropDownList(this HtmlControlHelper helper,
                                   string name, SelectList list, IDictionary <string, object> attributes)
 {
     return(SelectBuilder(helper, name, list, false, attributes));
 }
예제 #24
0
 public static string TextArea(this HtmlControlHelper helper,
                               string name, object attributes)
 {
     return(TextArea(helper, name, null, 2, 20, new ValueDictionary(attributes)));
 }
예제 #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)));
 }
예제 #26
0
 public static string TextArea(this HtmlControlHelper helper,
                               string name, string value)
 {
     return(TextArea(helper, name, value, 2, 20, new ValueDictionary()));
 }
예제 #27
0
 public static string ListBox(this HtmlControlHelper helper,
                              string name, MultiSelectList list)
 {
     return(ListBox(helper, name, list, null));
 }
예제 #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));
 }
예제 #29
0
 public static string ListBox(this HtmlControlHelper helper,
                              string name, MultiSelectList list, IDictionary <string, object> attributes)
 {
     return(SelectBuilder(helper, name, list, true, attributes));
 }
예제 #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));
 }