简单问:如何让文本框显示值.item.LastName上的代码失败
@model List<Mvc2010_11_12.Models.Employee>
@{
var grid = new WebGrid(source: Model,defaultSort: "FirstName",rowsPerPage: 3);
}
<div id="grid1">
@grid.GetHtml(columns: grid.Columns(
grid.Column("LastName"),
grid.Column(format: (item) => Html.TextBox("LastName", item.LastName))
))
</div>
Run Code Online (Sandbox Code Playgroud) 我需要返回给定日期的年份和星期.听起来很简单.但是要正确2012-01-01必须返回2011-52,因为2012年第1周从1月2日开始.
为了找到这一周,我使用:
GregorianCalendar calw = new GregorianCalendar(GregorianCalendarTypes.Localized);
return calw.GetWeekOfYear(DateTime.Parse("2012-01-01"), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday).ToString();
Run Code Online (Sandbox Code Playgroud)
这个回报52.(正确)
但是我怎么得到这一年?
编辑:
在这里的帮助:http://codebetter.com/petervanooijen/2005/09/26/iso-weeknumbers-of-a-date-ac-implementation/
这似乎有效:
private int weekYear(DateTime fromDate)
{
GregorianCalendar cal = new GregorianCalendar(GregorianCalendarTypes.Localized);
int week = weekNumber(fromDate);
int month = cal.GetMonth(fromDate);
int year = cal.GetYear(fromDate);
//week starts after 31st december
if (week > 50 && month == 1)
year = year - 1;
//week starts before 1st January
if (week < 5 && month == 12)
year = year + 1;
return year;
} …Run Code Online (Sandbox Code Playgroud)