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

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.
Justin HullAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MishaProgrammerCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Justin HullAuthor Commented:
That indeed did it, thank you very much for your help. You are awesome!!!
0
MishaProgrammerCommented:
Glad to help you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET MVC

From novice to tech pro — start learning today.