对于问题,当用户没有插入任何返回错误的错误时,如果没有空字符串,则为 @HtmlTextboxFor 。参数字典包含非空类型''fromdate'。参数的空条目。'
当用户插入一个空的字符串或者null作为值时,否则由用户插入的值。
我的代码有什么问题。public class ReportViewModel
{
public string FromDate { get; set; }
public string ToDate { get; set; }
private tDbContext tDbContext;
private IReportService reportService;
public void ViewReportList(DateTime fromDate, DateTime toDate)
{
reportService = new ReportService(tDbContext);
ReportList = reportService.GetReportsList(fromDate, toDate);
}
}
视图@model Req.ViewModels.ReportViewModel
@using (Html.BeginForm("Index","Print", FormMethod.Post))
{
@Html.TextBoxFor(m => m.FromDate, new { @readonly ="readonly", @class ="date-picker form-control"})
@Html.TextBoxFor(m => m.ToDate, new { @readonly = true, @class ="date-picker form-control"})
}
索引操作[HttpPost]
public ActionResult Index(ReportViewModel reportViewModel,DateTime FromDate, DateTime ToDate)
{
...
reportViewModel.ViewReportList(FromDate, ToDate);
return View("Index", reportViewModel);
}
建议后修改后的代码[HttpPost]
public ActionResult Index(ReportViewModel reportViewModel)
{
. . .
reportViewModel.ViewReportList(reportViewModel.FromDate, reportViewModel.ToDate);
return View("Index", reportViewModel);
}
ViewModelpublic class ReportViewModel
{
public DateTime? FromDate { get; set; }
public DateTime? ToDate { get; set; }
private tDbContext tDbContext;
private IReportService reportService;
public void ViewReportList(DateTime fromDate, DateTime toDate)
{
reportService = new ReportService(tDbContext);
ReportList = reportService.GetReportsList(fromDate, toDate);
}
}
现在我得到了这个错误它显示了错误ViewReportList ( system 。datetime 。system 。datetime )的最佳重载方法匹配
更改后。