I am trying to convert a C# DateTime variable into something that is able to be passed into a Javascript function through NewtonSoft.Json.
At the moment what I am using is:
var jsonSettings = new JsonSerializerSettings();
jsonSettings.DateFormatString = "dd/MM/yyy hh:mm:ss";
string modelFromDate = JsonConvert.SerializeObject(@Model.FromDate, jsonSettings);
However this does not seem to be working since when I use Chrome Dev Tools I get the error that
modelFromDate is not defined
in the following code:
$(".go").on("click", function () {
if (new Date(modelFromDate) < new Date(1994, 1, 1)) {
alert("invalid date");
}
});
I am using ASP.NET Core MVC.