Why do all rows pass id = 0 for edit function only

Justin
Justin used Ask the Experts™
on
I ran across an error I am having some trouble with and was hoping yall could help. I am using an jqgrid in MVC. I have no issues with the create or delete functions but for some reason I am passing a id value of 0 for all rows for my edit function. I am hoping I am overlooking a typo:

grid:
$('#TaskGrid').jqGrid({
            url: "/Users/getUsers",
            datatype: 'json',
            mtype: 'Get',
            colNames: ['UID', 'SID', 'DisplayName', 'isAdmin'],
            colModel: [
                { key: true, hidden: true, name: 'UID', index: 'UID', editable: false },
                { key: false, name: 'ID', index: 'ID', editable: true },
                { key: false, name: 'DisplayName', index: 'DisplayName', editable: true },
                { key: false, name: 'isAdmin', index: 'isAdmin', editable: true, filter: true }
            ],
            height: '100%',
            rowNum: 10,
            pager: jQuery('#jqControls'),
            viewrecords: true,
            caption: 'User Management',
            emptyrecords: 'No Records Found',
            jsonReader: {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: false,
                Id: "0"
            },
            autowidth: true

Open in new window


jqgrid edit function:
{
                zIndex: 100,
                url: '/Users/EditUser',
                closeOnEscape: true,
                closeAfterEdit: true,
                recreateForm: true,
                afterComplete: function (response) {
                    if (response.responseText) {
                        alert(response.responseText);
                    }
                }
            }

Open in new window


edit function:
public string EditUser(User Model)
        {
            string msg;
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(Model).State = EntityState.Modified;
                    db.SaveChanges();
                    msg = "Save Successfully";
                }
                else
                {
                    msg = "Validation of data not successful";
                }
            }
            catch (Exception ex)
            {
                msg = "Error: " + ex.Message;
            }
            return msg;
        }

Open in new window


when i debug the object being passed to the controler shows the correct data the the line i am editing, id, displayname, isAdmin but the primary key for the db, uid is always 0.

Thank you in advance for any help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You need to pass ID from client to server. In this case your model will be valid and can be saved in dataBase.
    { key: true, hidden: true, name: 'UID', index: 'UID', editable: true}

Open in new window

Try to set
editable: true

Open in new window

In this case you pass full model to server, but you can not edit but because
hidden: true

Open in new window

Author

Commented:
That indeed did it, thank you very much for your help. You are awesome!!!

Commented:
Glad to help you!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial