I'm having trouble creating a method in response to AJAX GET request from the Javacript. I have debugged it and it goes into the GET response method in the back-end and retrieves the proper data, but I am not sure how to return the data to the front.
Here is my code : Backend:
[HttpGet]
public ActionResult GetOldEntries()
{
var data = db.Entries.Where(e => e.Date.Month != DateTime.Now.Month);
return data; // How do I properly return data?
}
Front End:
$.get('/Home/GetOldEntries', function (data) {
console.log(data);
});
[HttpGet]
public ActionResult GetOldEntries()
{
var data = db.Entries.Where(e => e.Date.Month != DateTime.Now.Month);
return Json(data, JsonRequestBehavior.AllowGet);
}
Try the above
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With