I just run into a problem where i can't fetch data from SQL Table running a query. I have a GetData ActionResult in my controller i want to retrieve data in JSON format from the server but i am unable here is the code for the action:
public ActionResult GetData(int pageIndex, int pageSize)
{
    EFDbContext db = new EFDbContext();
    var query = (from c in db.Products
              orderby c.ProductName ascending
             select c)
             .Skip(pageIndex * pageSize)
             .Take(pageSize);
    return Json(query.ToList(), JsonRequestBehavior.AllowGet);
}
In my view i have placed this JQuery Ajax code to get data from the action and then append it to a container defined in the body of my view, here is the code.
<head>
    <title>Infinite Scroll</title>
    <script src="~/Scripts/jquery-1.10.2.js"></script>
    <script type="text/javascript">
        var pageSize = 10;
        var pageIndex = 0;
        $(document).ready(function () {
            GetData();
            $(window).scroll(function () {
                if ($(window).scrollTop() ==
                   $(document).height() - $(window).height()) {
                    GetData();
                }
            });
        });
        function GetData() {
            $.ajax({
                type: 'GET',
                url: '/Product/GetData',
                data: { "pageindex": pageIndex, "pagesize": pageSize },
                dataType: 'json',
                success: function (data) {
                    if (data != null) {
                        for (var i = 0; i < data.length; i++) {
                            $("#container").append("<h2>" +
                            data[i].ProductName + "</h2>");
                        }
                        pageIndex++;
                    }
                },
                beforeSend: function () {
                    $("#progress").show();
                },
                complete: function () {
                    $("#progress").hide();
                },
                error: function () {
                    alert("Error while retrieving data!");
                }
            });
        }
    </script>
</head>
I always get
500 (Internal server error)
, any idea?
 
    