Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC ActionResult How to return data in response to GET request

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);
});
like image 310
FluffyBeing Avatar asked Jan 18 '26 10:01

FluffyBeing


1 Answers

    [HttpGet]
    public ActionResult GetOldEntries()
    {
        var data = db.Entries.Where(e => e.Date.Month != DateTime.Now.Month);
        return Json(data, JsonRequestBehavior.AllowGet); 
    }

Try the above

like image 64
TGH Avatar answered Jan 20 '26 02:01

TGH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!