当我尝试删除学生代表时,我收到此错误消息..
问题描述:
The parameters dictionary contains a null entry for parameter 'date' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.ActionResult DeleteStudentAttendance(System.DateTime, Int64, Int64, Int32)' in 'CMS.ClientPortal.Controllers.TransController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
我尝试过:
What I have tried:
public ActionResult DeleteStudentAttendance(DateTime date, Int64 classId, Int64 divId,int timing)
{
if (LoggedInUser != null && LoggedInUser.IsAuthenticated)
{
TransactionRepositories.DeleteStudentAttendanceForDate(date, LoggedInUser.BranchId, LoggedInUser.InstituteId, classId, divId,timing);
TempData["actionresult"] = "Student Attendance Data For Class Deleted Successfully!!!";
return Json("success");
}
return Json("error");
}
答
您已经声明了一个将DateTime作为第一个参数的方法 - 和DateTime是一个值类型,这意味着它可以接受null
值,这是你传递给它的值。
阅读错误消息,它解释了为了使它与现有数据一起工作所必须做的事情,但是我会查看调用该方法的代码并找出为什么你的代码认为它是好的想要一个null
的日期......
You've declared a method which takes a DateTime as the first parameter - and DateTime is a Value Type, which means it can;t accept anull
value, which is what you are passing to it.
Read the error message, and it explains what you have to do in order to make it work with your existing data, but I'd look at the code that calls the method and work out why your code thinks it's a good idea to have anull
date at all ...