locked
500 (Internal Server Error) RRS feed

  • Question

  • User1555868569 posted

    Hi everyone. when I am running my code I got a error " Failed to load resource: the server responded with a status of 500 (Internal Server Error)" I am using two tables one is Order and OrderDetails, there are relationship between them.

    This is my index javascript code:

    <script>
    $(document).ready(function () {
    $("#ordenTrabajo").DataTable({
    "ajax": {
    "url": "/Home/GetData",
    "type": "GET",
    "datatype": "json"

    },
    "columns": [
    { "data": "OrderID" },
    { "data": "OT" },
    { "data": "Cliente" },
    { "data": "Tipo" },
    { "data": "NumParte" },
    { "data": "FechaIni" },
    { "data": "FechaFin" },

    ]

    });

    });
    $.fn.dataTable.ext.errMode = 'throw';
    </script>

    This is my Control code:

    public class HomeController : Controller
    {
    // GET: Home
    public ActionResult Index()
    {
    return View();
    }

    public JsonResult GetData()
    {
    InselDBEntities1 dc = new InselDBEntities1();
    List<Order> orderList = dc.Orders.ToList();
    return Json(orderList, JsonRequestBehavior.AllowGet);
    }

    }

    Image with more details. 

    https://drive.google.com/open?id=1SPBdSNOAiwAHwtSUEvTFExJCczQdrj6Q

    Please help me out!!!

    Thanks. 

    Thursday, June 28, 2018 1:27 PM

All replies

  • User-330142929 posted

    Hi Morbanjunior,

    According to your description, I think you may forget assign the "sAjaxDataProp" property,

    When we fetch the serversided json, we should assign the key which will return the data,

    Just like this.

    Serverside json.

    {
    "iTotalRecords":"6",
    "iTotalDisplayRecords":"6",
    "aaData": [
        [
            "1",
            "sameek",
            "sam",
            "sam",
            "sameek@test.com",
            "1",
            ""
    ],...

    We should set the "sAjaxDataProp": “aaData”

    I have made a demo, wish it is useful to you.

    Razor.

    <div>
            <table id="table1" class="display">
                <thead>
                    <tr>
                        <th>Id</th>
                        <th>Name</th>
                        <th>Price</th>
                    </tr>
                </thead>
            </table>
    </div>  

    Script.

    <script>
            $(document).ready(function () {
                $('#table1').DataTable({
                    //"processing" : true,
                    //"serverSide" : true,
                    "ajax": {
                        "url": "/Home/GetData",
                        "type":"Get"
                    },
                    "sAjaxDataProp": "",
                    "columns": [
                        { "data": "Id" },
                        { "data": "Name" },
                        { "data": "Price" },
                    ]
                });
            });
    </script>

    Controller.

    public JsonResult GetData()
            {
                List<Product> products = new List<Product>()
                {
                    new Product{Id=1,Name="Apple",Price=11 },
                    new Product{Id=2,Name="Pear",Price=12 }
                };
                return Json(products, JsonRequestBehavior.AllowGet);
            }
            // GET: Home
            public ActionResult Index()
            {
                return View();
            }
        }
        public class Product
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public int Price { get; set; }
     
        }

    And here is the serverside json, 

    [{"Id":1,"Name":"Apple","Price":11},{"Id":2,"Name":"Pear","Price":12}]

    How it works

    Here is relevant link.

    https://stackoverflow.com/questions/22470411/datatables-cannot-read-property-length-of-undefined

    Please feel free to let me know if you have any question.

    Best Regards,

    Abraham.

    Friday, June 29, 2018 8:26 AM
  • User1555868569 posted

    Hi thanks for your answer I added sajaxDataProp but I continue have the problem, if it possible for you, write a example but with data base. and look all my picture in the link. 

    Friday, June 29, 2018 2:54 PM
  • User-330142929 posted

    Hi Morbanjunior,

    According to your description, I have written a demo with database by using EntityFramework.

    And it does not seem to be a problem here.

    Result.

    I suggest you could add a breakpoint through F9 to see if the List<T> is returned correctly. Is your DbContext class configured correctly, Is your EF connection string wrong?

    Feel free to let me know if you have any question.

    Best Regards,

    Abraham.

    Saturday, June 30, 2018 9:07 AM
  • User1555868569 posted

    Hi. I have putted a breakpoint in List<Order> orderList = dc.Orders.ToList(); and it is returned NULL.

    details.

    breakpoint

    Tuesday, July 3, 2018 1:09 PM
  • User-330142929 posted

    Hi Morbanjunior,

    From you description, I think the problme should be here. I suggest you check if there is a record in the data. And then we could retrieve the data by using the EF framework. You could refer the following tutorial.

    https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ef/getting-started

    https://msdn.microsoft.com/en-us/library/aa937723(v=vs.113).aspx

    Feel free to let me know if you have any question.

    Best Regards

    Abraham

    Tuesday, July 3, 2018 2:50 PM
  • User1555868569 posted

    Hi. let me explain something , I have another module where I can save data in the two table. it is the same table that I am trying to show in table. as you can see, I have a form where in can input data in to table one of them is Order and OrderDetails. 

    Tuesday, July 3, 2018 3:39 PM
  • User-330142929 posted

    Hi Morbanjunior,

    Sorry to tell you that the current thread should be closed since it has been resolved. In order to make it easier for others to search problems, I suggest you could post a new thread to ask a new question. Thank you for understanding our work.

    Best Regards

    Abraham.

    Wednesday, July 4, 2018 3:01 AM
  • User1555868569 posted

    Hi! but I still have the problem! that's problem is still happening!! the img I posted is about another module I have it. 

    Wednesday, July 4, 2018 12:14 PM
  • User-330142929 posted

    Hi Morbanjunior,

    According to your description,

    Hi! but I still have the problem! that's problem is still happening!!

    I think the problem may be caused by the SQL Server, would you mind providing more information about your Orders tables, such as data records, table structure design.

    I suggest you could put the breakpoint to the following position in order to see more error details.

    Feel free to let me know If you have any question.

    Best Regards

    Abraham

    Thursday, July 5, 2018 6:32 AM