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)'
I'm sure the problem is from params of date, i don't know why, Can you help me to figure out
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.
Member
8 Points
85 Posts
adding date range parameter $.getJSON to integrate with controller json asp mvc
Dec 01, 2019 05:23 AM|hocamahdi99|LINK
I want to parameters range date in getjson jquery here is my code
Here is my controller
here is the generated request url on network http://localhost:35039/searchstatistics/GetData?from=28-11-2019&to=01-12-2019 I got error below
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)'
I'm sure the problem is from params of date, i don't know why, Can you help me to figure out
Contributor
3140 Points
983 Posts
Re: adding date range parameter $.getJSON to integrate with controller json asp mvc
Dec 02, 2019 02:32 AM|Yang Shen|LINK
Hi hocamahdi99,
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:
Below is the result of above demo:
Best Regard,
Yang Shen