Parse data from editor into a Json object from rest (MVC WebApi) server side

Parse data from editor into a Json object from rest (MVC WebApi) server side

JasonColeyNZJasonColeyNZ Posts: 11Questions: 4Answers: 0

This is what I have in the ApiController, this is being hit, but I need to parse the object as I need to do processing before it is passed to another web service

    [HttpPost]
    public IHttpActionResult Part( )
    {
        var request = HttpContext.Current.Request;
       //how can i get <PartList> object from request?
       return Json (new {success = true });
    }

Answers

  • JasonColeyNZJasonColeyNZ Posts: 11Questions: 4Answers: 0
    var editor;
    
    function InitTable(ManualID)
    {
        $('#Parts').dataTable().fnDestroy();
    
        $('#Parts').dataTable({
            ajax: "Home/Read_Parts/" + ManualID,
            dom: 'Tfrtip',
            lengthChange: false,
            paginate: false,
            processing: true,
            columns: [
                { data: "ManualName" },
                { data: "SectionNoName" },
                { data: "PartSectionNo" },
                { data: "Code" },
                { data: "Description" },
                { data: "UnitPrice", render: $.fn.dataTable.render.number( ',', '.', 0, '$' )}
            ],
            tableTools: {
                sSwfPath: "/Scripts/DataTables-1.10.7/extensions/TableTools/swf/copy_csv_xls_pdf.swf",
                sRowSelect: 'os',
                aButtons: [
                    { sExtends: 'editor_create', editor: editor },
                    { sExtends: 'editor_edit', editor: editor },
                    { sExtends: 'editor_remove', editor: editor}
    ]
            }
        }).rowGrouping(
        {
            bExpandableGrouping: true,
            bExpandableGrouping2: true,
            sGroupingClass: "group1",
            sGroupingClass2: "group2",
            iGroupingColumnIndex: 1,
            iGroupingColumnIndex2: 2,
            iGroupingColumnIndex: 0,
            iGroupingColumnIndex2: 1
        });
    }
    
    $(document).ready(function () {
    
        $("#Manuals").change(function () {
            InitTable($("#Manuals").val());
        });
    
        editor = new $.fn.dataTable.Editor({
            ajax: "api/part", 
            table: '#Parts',
            fields: [
                { label: 'Section Number', name: 'PartSectionNo' },
                { label: 'Supplier Code', name: 'Code' },
                { label: 'Description', name: 'Description' },
                { label: 'Buy Price (US)', name: 'UnitPrice' },
                { label: 'Sell Price (NZ)', name: 'SellPrice' },
                { label: 'Stock Level', name: 'Level' },
                { label: 'Warning Level', name: 'Warning' },
                { label: 'SKU', name: 'SKU' }
            ]
        });
    
        editor
            .on('open', function (e, type) {
                if (type === 'inline') {
                    // Listen for a tab key event when inline editing
                    $(document).on('keydown.editor', function (e) {
                        if (e.keyCode === 9) {
                            e.preventDefault();
    
                            // Find the cell that is currently being edited
                            var cell = $('div.DTE').parent();
    
                            if (e.shiftKey && cell.prev().length && cell.prev().index() !== 0) {
                                // One cell to the left (skipping the first column)
                                cell.prev().click();
                            }
                            else if (e.shiftKey) {
                                // Up to the previous row
                                cell.parent().prev().children().last(0).click();
                            }
                            else if (cell.next().length) {
                                // One cell to the right
                                cell.next().click();
                            }
                            else {
                                // Down to the next row
                                cell.parent().next().children().eq(1).click();
                            }
                        }
                    });
                }
            })
            .on('close', function () {
                $(document).off('keydown.editor');
            });
    
        $('#Parts').on('click', 'tbody td:not(:first-child)', function (e) {
            editor.inline(this, {
                submitOnBlur: true
            });
        });
    
        InitTable(-1);
    });
    
This discussion has been closed.