【发布时间】:2016-03-26 19:59:46
【问题描述】:
我只是想在我的 MVC 应用程序中返回日期并且遇到了问题。我已经申请了我的模型DataFormatString = "{0:dd/M/yy}",并且还包括ApplyFormatInEditMode = true,正如这些帖子ASP.NET MVC displaying date without time和Displaying Date only MVC所建议的那样
然而,我正在生成该字段以将接下来 5 周的开始日期包含在下拉列表中,如下所示 http://prntscr.com/ak825u。
这是通过以下代码完成的
// GET: TimeSheets/Create
public ActionResult Create()
{
int weekCount = 5;
List<DateTime> listDates = new List<DateTime>();
for (int i = 0; i < (weekCount * 7); ++i) //Get next 5 weeks
{
//Adds only next 5 mondays to the list of dates
if (DateTime.Today.AddDays(i).DayOfWeek == DayOfWeek.Monday)
listDates.Add(DateTime.Today.AddDays(i));
}
ViewData["DateList"] = new SelectList(listDates);
return View();
}
我将如何删除时间以仅显示日期
【问题讨论】:
-
这取决于您使用的是哪种网络控件。 .NET 没有问题,但渲染是浏览器的责任。或者,您可以填充字符串列表而不是 DateTime。
标签: c# asp.net asp.net-mvc asp.net-mvc-4