Checkboxlist HTMLHelper

Last post 04-02-2008 10:58 AM by mdrgow. 4 replies.

Sort Posts:

  • Checkboxlist HTMLHelper

    04-01-2008, 5:25 PM
    • Member
      7 point Member
    • mdrgow
    • Member since 03-26-2008, 7:57 AM
    • Posts 19

    Does anyone know if this has been removed permanently and does anyone know of any custom extension methods out there to achieve this?

    It seems strange that they decided to remove this in Preview 2. Tongue Tied

    Thanks in advance.

  • Re: Checkboxlist HTMLHelper

    04-02-2008, 8:22 AM
    • Member
      368 point Member
    • maartenba
    • Member since 01-23-2008, 1:27 PM
    • Belgium
    • Posts 76

    These are available, in the namespace System.Web.Mvc (class System.Web.Mvc.HtmlHelper)

    Forget MvcContrib as it is removed from CTP 2.

    Visit my blog at http://blog.maartenballiauw.be

    Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
  • Re: Checkboxlist HTMLHelper

    04-02-2008, 8:44 AM
    • Member
      7 point Member
    • mdrgow
    • Member since 03-26-2008, 7:57 AM
    • Posts 19

    The CheckboxList Helper is not there.

    There is still a CheckBox helper there but no CheckBoxList anymore.

    I can get around this by writing my own loop and writing the HTML but it would have been nice to use this and I don't know why it's been removed from from CTP 2 as it was there in CTP 1.

  • Re: Checkboxlist HTMLHelper

    04-02-2008, 9:48 AM
    Answer
    • Member
      368 point Member
    • maartenba
    • Member since 01-23-2008, 1:27 PM
    • Belgium
    • Posts 76

    Here's an extension method which will probably work as expected:

        public static class  CheckBoxListExtensions
        {
            public static string[] CheckBoxList(this HtmlHelper htmlHelper, string htmlName, object dataSource, string textField, string valueField, object selectedValue, RouteValueDictionary htmlAttributes)
            {
                List<string> list = new List<string>();
                Dictionary<object, object> dictionary = MvcControlDataBinder.SourceToDictionary(dataSource, valueField, textField);
                foreach (object obj2 in dictionary.Keys)
                {
                    string str = obj2.ToString();
                    string text = (dictionary[obj2] == null) ? string.Empty : dictionary[obj2].ToString();
                    bool isChecked = selectedValue.Equals(str);
                    string item = CheckBoxBuilder.CheckBox(htmlName, text, str, isChecked, htmlAttributes);
                    list.Add(item);
                }
                return list.ToArray();
            }
        }

    Visit my blog at http://blog.maartenballiauw.be

    Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
  • Re: Checkboxlist HTMLHelper

    04-02-2008, 10:58 AM
    • Member
      7 point Member
    • mdrgow
    • Member since 03-26-2008, 7:57 AM
    • Posts 19

    Yes this has helped.

     

    Thankyou. 

Page 1 of 1 (5 items)