I don't get any Json response data

I don't get any Json response data

sanderksanderk Posts: 26Questions: 4Answers: 1

Hi,

I have the following code:

[Authorize]
    public class AdministratiesController : Controller
    {
        private readonly IConfiguration _configuration;


        public AdministratiesController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        [Route("administraties/table")]
        [HttpGet]
        [HttpPost]
        public ActionResult Table()
        {
            string connectionString = _configuration.GetConnectionString("BBGroepDataContext");

            using (var db = new Database("sqlserver", connectionString))
            {

                var response = new Editor(db, "Administraties")
                    .Model<Administratie>()
                    .Field(new Field("Naam")
                        .Validator(Validation.NotEmpty())
                    )
                    .Debug(true)
                    .TryCatch(false)
                    .Process(Request)
                    .Data();

                return Json(response);
            }
        }
    }

The reponse contains multiple records, but I don't get any Json written to the browser.

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Can you post the JSON and the table initialisation code too, please.

    Colin

  • sanderksanderk Posts: 26Questions: 4Answers: 1

    I don't get any json response. Just {}

  • sanderksanderk Posts: 26Questions: 4Answers: 1

    And when I continue

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    You said the response contains multiple records. Show them to us. Colin also asked to see your DataTable initialisation code.

  • sanderksanderk Posts: 26Questions: 4Answers: 1

    The screenshot shows the response object has four records. This is the code I have in the HTML page:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, user-scalable=no">
        <title>Editor example - Basic initialisation</title>
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.6.1/css/buttons.dataTables.min.css">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css">
        <link rel="stylesheet" type="text/css" href="./css/editor.dataTables.min.css">
        <link rel="stylesheet" type="text/css" href="./resources/syntax/shCore.css">
        <link rel="stylesheet" type="text/css" href="./resources/demo.css">
        <style type="text/css" class="init">
    
        </style>
        <script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
        <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
        <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.6.1/js/dataTables.buttons.min.js"></script>
        <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js"></script>
        <script type="text/javascript" language="javascript" src="./js/dataTables.editor.min.js"></script>
        <script type="text/javascript" language="javascript" src="./resources/syntax/shCore.js"></script>
        <script type="text/javascript" language="javascript" src="./resources/demo.js"></script>
        <script type="text/javascript" language="javascript" src="./resources/editor-demo.js"></script>
        <script type="text/javascript" language="javascript" class="init">
    
    
    
            var editor; // use a global for the submit and return data rendering in the examples
    
            $(document).ready(function () {
                editor = new $.fn.dataTable.Editor({
                    ajax: "administraties/table",
                    table: "#example",
                    fields: [{
                        label: "Naam:",
                        name: "Naam"
                    }
                    ]
                });
    
                $('#example').DataTable({
                    dom: "Bfrtip",
                    ajax: "administraties/table",
                    columns: [
                        { data: "Naam" }
                    ],
                    select: true,
                    buttons: [
                        { extend: "create", editor: editor },
                        { extend: "edit", editor: editor },
                        { extend: "remove", editor: editor }
                    ]
                });
            });
    
    
    
        </script>
    </head>
    <body class="dt-example net">
        <div class="container">
            <section>
                <table id="example" class="display" style="width:100%">
                    <thead>
                        <tr>
                            <th>Naam</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>Naam</th>
                        </tr>
                    </tfoot>
                </table>
            </section>
        </div>
    </body>
    </html>
    
  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Could you add in the .Debug(true) like you have in the code in your original post (but not the screenshot) and then use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    Thanks,
    Allan

  • sanderksanderk Posts: 26Questions: 4Answers: 1
  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Thanks! That shows that the response from the server is:

    "responseText": "{}",

    So I don't understand why the debugger in the screenshot would be showing that there are four rows in the returned data.

    Could you add .Debug(true) before the .Process(...)` method call please, and then run the debugger on it again to give me another trace?

    Thanks,
    Allan

  • sanderksanderk Posts: 26Questions: 4Answers: 1
  • sanderksanderk Posts: 26Questions: 4Answers: 1

    I'm using .net core 3.1

  • sanderksanderk Posts: 26Questions: 4Answers: 1
    Answer ✓

    I fixed it.

    It is important to instaal nuget package

    Microsoft.AspNetCore.Mvc.NewtonsoftJson

    And add the configuration lines in startup.cs. Like in the example. If you don't install this package, you won't get any errors (Framework 3.x) but it doesn't work.

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin
    Answer ✓

    Thanks for posting back - great to hear you've got it working.

    Allan

This discussion has been closed.