0

Hello I am working on Kendo UI grid. I want to update grids changes in database. Grid itself is working normally but I cannot pass my grids changed values to C# code to change in database. I can call C# method(Update) from kendo UI Grid but cannot pass values to Controllers method it is empty.

here is my HTML code and jQuery

<div id="gridKendo"></div>
 
<script type="text/javascript">

$(document).ready(function() {
        $("#gridKendo").kendoGrid({
        dataSource: CustomerHelper.gridDataSource(),
        
        schema: {
            model: {
                id: "Id",   
                fields: {
                    Id: { type: "number" },
                    Payroll_Number: { type: "string" },
                    Forenames: { type: "string" },
                    Surenames: { type: "string" },
                    Date_of_Birth: { type: "string" },
                    Telephone: { type: "string" },
                    Mobile: { type: "string" },
                    Address: { type: "string" },
                    Address_2: { type: "string" },
                    Postcode: { type: "string" },
                    EMail_Home: { type: "string" },
                    Start_Date: { type: "string" },
                }
            }
        },
        columns: CustomerHelper.GenerateColumns(),
        type: "odata",
        editable: "inline",
        navigatable:true,
        selectable: "multiple, row",           
     });
});
var CustomerHelper = {
    GenerateColumns: function() {
        return columns = [
            {field: "Id", title:"Id" , width: 160, editable:false, hidden: true},
            {field: "Payroll_Number", title:"Payroll Number" , width: 160, editable:false , validation: { required: true}},
            {field: "Forenames", title:"Forename" , width: 160, editable:false ,hidden: true},
            {field: "Surenames", title:"Surename" , width: 160, editable:false, hidden: true},
            {field: "Date_of_Birth", title:"Date of Birth" , width: 160, editable:false, hidden: true},
            {field: "Telephone", title:"Telephone" , width: 160, editable:false ,hidden: true},
            {field: "Mobile", title:"Mobile " , width: 160, editable:false ,hidden: true},
            {field: "Address", title:"Address" , width: 160, editable:false ,hidden: true},
            {field: "Address_2", title:"Address second" , width: 160, editable:false ,hidden: true},
            {field: "Postcode", title:"Postcode" , width: 160, editable:false ,hidden: true},
            {field: "EMail_Home", title:"EMail_Home" , width: 160, editable:false ,hidden: true},
            {field: "Start_Date", title:"Date of start" , width: 160, editable:false ,hidden: true},
            { command: [{name: "edit", text: {edit: "Edit", update: "Update", cancel: "Cancel" }}],width: 160}
        ]
    },
    
    gridDataSource: function(){

        var gridDataSource = new kendo.data.DataSource({
            pageSize: 5,
            batch: true,
            schema: {
                data: "Items", total: "TotalCount", // used for data read
                model: {
                   id: "Id", 
                    fields: {
                        Id: { type: "number" },
                        Payroll_Number: { type: "string", validation: { required: { message: "Please enter a last name for this employee"  } } },
                        Forenames: { type: "string" },
                        Surenames: { type: "string" },
                        Date_of_Birth: { type: "string" },
                        Telephone: { type: "string" },
                        Mobile: { type: "string" },
                        Address: { type: "string" },
                        Address_2: { type: "string" },
                        Postcode: { type: "string" },
                        EMail_Home: { type: "string" },
                        Start_Date: { type: "string" },
                    }
                }
            },
            transport: {
                update: {
                    url: '../Personnel_Records/update', 
                    dataType: "json",
                    type: "POST",
                },
                parameterMap: function(options, operation ) {
                   if (operation !== "read" && options.models) 
                   {
                       return { models: kendo.stringify(options.models) };
                   }   
                }
            },
        });
        return gridDataSource;
    },
}
</script>

here is my Controller

using CsvHelper.Configuration;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Globalization;
using Task.Models;


namespace Task.Controllers
{
    public class Personnel_RecordsController : Controller
    {
    public JsonResult update(string res)
        {
             // logic should be but result is null
        }
    }
xoja
  • 11
  • 2

1 Answers1

0

I managed to this by extracting values from url just added this in my controller

var form = Request.Form;
var models = JsonConvert.DeserializeObject<IEnumerable<Personnel_Records>>(Request.Form.FirstOrDefault().Value);

I get answer from here.

xoja
  • 11
  • 2