User-719153870 posted
Hi hocamahdi99,
The parameters dictionary contains a null entry for parameter 'from' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.JsonResult GetData(System.DateTime, System.DateTime)'
The reason for this problem is that you were trying to pass a from value with incorrect format to your GetData method.
The correct method for a datetime type value in c# should be like
MM-DD-YYYY, YYYY-MM-DD, YYYY/MM/DD or MM/DD/YYYY etc but not
DD-MM-YYYY.
Please modify your code like below demo:
cshtml:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>FromToDemo</title>
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script>
function get() {
var params = { from: "11-28-2019", to: "12-01-2019" };
$.getJSON('/Demo/GetData', params, function (result) {
alert(result);
});
}
</script>
</head>
<body>
<div>
<input type="button" value="Get" onclick="get()" />
</div>
<p></p>
</body>
</html>
cs:
public ActionResult FromToDemo()
{
return View();
}
public JsonResult GetData(DateTime from, DateTime to)
{
string a = from.ToString()+"abc"+to.ToString();
return Json(a, JsonRequestBehavior.AllowGet);
//another code goes here
}
Below is the result of above demo:

Best Regard,
Yang Shen