albert albert

albert albert

  • NA
  • 524
  • 0

select from dropdownbox

May 21 2012 10:13 AM
Hi everybody,

I have this:

[code]
 public static IEnumerable<SelectListItem> GetWeekNumbers(this HtmlHelper helper /*Dictionary<int, DateTime> dayOfWeek*/  /*,DateTime allWeeks*/ /*int selectID*/)
        {
            var janFirst = new DateTime(DateTime.Today.Year, 1, 1);
            //beware different cultures.
            var firstWeek = janFirst.AddDays(1 - (int)(janFirst.DayOfWeek));
            int j = -1;
            foreach (var x1 in Enumerable.Range(0, 52).Select(i => new
            {
                weekStart = firstWeek.AddDays(i * 7),
                Tuesday = firstWeek.AddDays(i * 3)
            }).TakeWhile(x => x.weekStart.Year <= janFirst.Year).Select(x => new
            {
                x.weekStart,

                tuesday = x.weekStart.AddDays(3),
                weekFinish = x.weekStart.AddDays(6)
            }).SkipWhile(x => x.weekFinish < janFirst.AddDays(1)))
            {
                j++;
                yield return new SelectListItem
                {
                    Text = new
                    {
                        maandag = firstWeek.AddDays(j * 7).ToShortDateString()
                        //Dindsdag = x1.weekStart.AddDays(1).ToShortDateString(),
                        //vrijdag = x1.weekStart.AddDays(6).ToShortDateString(),
                        //weekNum = j + 1
                    }.ToString(),

                   
                    //Value = (j + 1).ToString(CultureInfo.InvariantCulture)

                 
                };               
            }

            //return helper.DropDownList()
        }//end method
[/code]

And this:

[code]
public static MvcHtmlString StateDropDown(this HtmlHelper helper,string name, DateTime date)
        {
            return MvcHtmlString.Create(value: Enumerable.Select(GetWeekNumbers(helper), x => x.Text).ToString());

            //return MvcHtmlString.Create((GetWeekNumbers(helper).First().Text));
        }//end method
[/code]

and for the view:

[code]
td>
                    <div class="editor-label">
                       @Html.LabelFor(model => model.Tuesday, "Dinsdag")
                    </div>
                    <div class="editor-field">
                        @Html.TextBox("Hallo", Html.StateDropDown(null, new DateTime()))
                        @Html.ValidationMessageFor(model => model.Tuesday)
                    </div>
                </td>
[/code]

But i get as output:

System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Web.Mvc.SelectListItem,System.String]

in the texbox

THX for helping.



Answers (18)