DateTimeFormatInfo()和FirstDayOfWeek的html帮助问题

我有一个小问题,今天让我烦恼!我已经创建了一个小帮手方法,我希望它总是在星期一作为一周的第一天(即星期一= 0)返回,但似乎无法弄清楚我哪里出错了。我正在设置我'感觉'是对现有文化的超越,但无济于事。 不用多说,代码:
public static string ComboDaysOfWeekNumber(this HtmlHelper helper, 
                     string id, string selectedValue)
{
    var cultureInfo = new DateTimeFormatInfo();
    cultureInfo.FirstDayOfWeek = DayOfWeek.Monday;
    var newitems = cultureInfo
        .DayNames
        .Select((dayName, index) => new SelectListItem
        {
            Value =(index).ToString(),
            Text = dayName,
            Selected = (selectedValue == dayName)
        });

    var result = helper.DropDownList(id, newitems).ToHtmlString();
    return result;
}
用法:
<%=Html.ComboDaysOfWeekNumber("weekSplitEnd", myModelDayNo.ToString())%>
无论如何,这总是在星期日= 0开始。 有什么想法?     
已邀请:
DayNames
不依赖于
FirstDayOfWeek
属性并设置它不会产生任何影响。你可以试试这个:
var cultureInfo = new DateTimeFormatInfo();
var dayNames = new[] 
{
    DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, 
    DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, 
    DayOfWeek.Sunday 
}.Select(cultureInfo.GetDayName);

var newitems = dayNames
    .Select((dayName, index) => new SelectListItem
    {
        Value =(index).ToString(),
        Text = dayName,
        Selected = (selectedValue == dayName)
    });

var result = helper.DropDownList(id, newitems).ToHtmlString();
return result;
    
达林, 现在回来,这就是我提出的问题:
public static MvcHtmlString ComboDaysOfWeekNumber(this HtmlHelper helper, 
                              string id, int selectedValue)
{

    var dayNames = new[]
                       {
                           DayOfWeek.Monday, DayOfWeek.Tuesday, 
                           DayOfWeek.Wednesday, DayOfWeek.Thursday, 
                           DayOfWeek.Friday, DayOfWeek.Saturday,
                           DayOfWeek.Sunday
                       };

    var newitems = dayNames
        .Select((dayName, index) => new SelectListItem
        {
            Value =(index).ToString(),
            Text = dayName.ToString(),
            Selected = (selectedValue == index)
        });

    var result = helper.DropDownList(id, newitems);
    return result;
}
这似乎“按预期工作”。谢谢你的指点。 吉姆     

要回复问题请先登录注册