我正在开展一个报告时间报告的项目.现在我正在开发一个可以报告假期的功能.从迄今为止.但是,当您只需单击按钮发送而无需在我的两个字段中输入任何内容时,它将因为null异常而崩溃.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(DateTime fromDate, DateTime toDate, string comment)
{
using (IDatabaseLayer db = new DatabaseLayer())
{
if (fromDate != null || toDate != null)
{
db.InsertVacation(Constants.CurrentUser(User.Identity.Name), fromDate, toDate, comment);
ViewData.Model = db.GetUserVacations(Constants.CurrentUser(User.Identity.Name));
}
}
SendVacationMail(fromDate, toDate, comment);
ViewData["posted"] = true;
return View();
}
Run Code Online (Sandbox Code Playgroud)
在调试它时,它不会触及此代码块,除非我的字段中包含值.
我这里有这个小代码:
@foreach (var date in ViewBag.MissingDays)
{
var isoDate = date.ToString("yyMMdd");
<div class="col-md-1">
<input type="checkbox" id="isoDate" name="isoDate" value="@isoDate" />
@isoDate
</div>
}
Run Code Online (Sandbox Code Playgroud)
那将打印出我错过的视图中的所有日期,就像你可以看到它打印出来的像"yymmdd yymmdd yymmdd"等,但很难知道它是什么工作日,所以我想成为"mo yymmdd" tu yymmdd我们yymmdd"所以这是当天的两个首字母,我怎么能实现这个?