Error: ther server responded with a status of 500

Error: ther server responded with a status of 500

mpmmpm Posts: 15Questions: 8Answers: 0

I'm working on MVC application, and when I tried to display my datatable I got this Ajax error. Can you help me please?

Answers

  • kthorngrenkthorngren Posts: 21,352Questions: 26Answers: 4,955

    To start with you will need to look at your server logs to see why its returning the 500 error.

    Kevin

  • mpmmpm Posts: 15Questions: 8Answers: 0
    edited March 2018

    Thank you for your reply,the problem is in my GetList method according to this message:

    , am I missing something this is my Controller:

    namespace wb01.Controllers![](https://datatables.net/forums/uploads/editor/ac/oqtddb8ba3bm.png "")
    
    {
        public class ConsommationsController : Controller
        {
            private database db = new database();
     
            // GET: Consommations
            public ActionResult Index()
            {
                var consommation = db.Consommation.Include(c => c.Unités_de_prod);
     
                return View();
            }
         [HttpPost]
            public ActionResult GetList()
            {
               List<Consommation> listconsom = new  List<Consommation>();
                using (database db = new database())
                {
                listconsom = db.Consommation.ToList<Consommation>();
              
                }
      return Json(new { data = listconsom }, JsonRequestBehavior.AllowGet);
            }
    

    And this is my View:


    @model IEnumerable<wb01.Models.Consommation> <br /><br /><br /><br /><br /><br /> <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables.css"> <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables_themeroller.css"> <br /> <p> @Html.ActionLink("Create New", "Create") </p> <table @*class="display"*@ id="tableconsommation"> <thead> <tr> <th>Date_consommation</th> <th>Qtité_consommée</th> <th>Id_unité</th> <th>Unités_de_prod</th> </tr> </thead> <tfoot> <tr> <th>Date_consommation</th> <th>Qtité_consommée</th> <th>Id_unité</th> <th>Unités_de_prod</th> </tr> </tfoot> </table> @section scripts { <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/jquery.dataTables.min.js"></script> <script> $(document).ready(function () { $("#tableconsommation").dataTable({ "ajax": { "url": "/Consommations/GetList", "type": "POST", "datatype": "json" }, "columns": [ { "data": "Date_consommation", "data": "Date_consommation" }, { "data": "Qtité_consommée", "data": "Qtité_consommée" }, { "data": "Id_unité", "data": "Id_unité" }, { "data": "Unités_de_prod", "data": "Unités_de_prod" }, ], "serverSide": "true", "order": [0, "asc"], "processing": "true", }); }); </script> }
  • kthorngrenkthorngren Posts: 21,352Questions: 26Answers: 4,955

    Have you looked at the logs on your server to see why the server is responding with the 500 error?

    Kevin

  • mpmmpm Posts: 15Questions: 8Answers: 0

    sorry but I don't know how to do that, using Elmah?

This discussion has been closed.