ASP.NET MVC won't call ActionResult from dataTable.editor function

ASP.NET MVC won't call ActionResult from dataTable.editor function

cworkmani21cworkmani21 Posts: 2Questions: 1Answers: 1

Hello,

I'm having an issue where my .cshtml document is not calling the ActionResult method in my controller.

I've been able to make a button to force it via

@Url.Action("EditorTable")

However, when I put that same controller action into the ajax parameter of the dataTable.Editor function it's not called.

My controller is returning the correct data from the server, but the data table itself isn't being generated.

JSON Result:

Here's my .cshtml script
`
var editor; // use a global for the submit and return data rendering in the examples

$(document).ready(function () {
    editor = new $.fn.dataTable.Editor({
        ajax: '@Url.Action("EditorTable")',
        table: "#opportunities",
        fields: [{
            label: "Opportunity:",
            name: "OpportunityName"
        }, {
            label: "Proposal Date:",
            name: "ProposalDate"
        }, {
            label: "Probability",
            name: "Probability"
        }, {
            label: "Client Type:",
            name: "ClientType"
        }, {
            label: "Notes: ",
            name: "Notes"
        }, {
            label: "Description: ",
            name: "Description"
        }
        ]
    });

    $('#opportunities').DataTable({
        //dom: "Bfrtip",
        ajax: {
            url: '@Url.Action("EditorTable")',
            type: 'POST'
        },
        columns: [
            { data: "OpportunityName" },
            { data: "ProposalDate" },
            { data: "Probability" },
            { data: "ClientType" },
            { data: "Notes" },
            { data: "Description" }

        ],
        select: true,
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit", editor: editor },
            { extend: "remove", editor: editor }
        ]
    });
});

editor();

`

Any thoughts on what I'm doing wrong? Help would be greatly appreciated!!!

Thanks,
Channing

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Hi Channing,

    In the browser if you right click and select "View source" what does it show the url being rendered as?

    Thanks,
    Allan

  • cworkmani21cworkmani21 Posts: 2Questions: 1Answers: 1
    Answer ✓

    Hi Allan,

    I was able to fix my issue once I figured out how to actually debug. I'm not much of a web dev. Anyway, I was having issues with multiple jquery loadings because ASP.NET MVC has a _Layout file that bundled jquery!

    Fixed the duplication issue and we're moving along!

    Thank you for your response.

    Channing

This discussion has been closed.