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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.