Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6029119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:50:23+00:00 2026-05-23T04:50:23+00:00

I have jqGrid with enabled EDIT, DELETE, ADD and VIEW , Now my problem

  • 0

I have jqGrid with enabled EDIT, DELETE, ADD and VIEW, Now my problem is when i click on edit button then it will success fully open Dialog with edit mode. now when i am submitting my changes then it will pass jqGrid Row Index instead of ColID (ColId is PK with AutoIdentity True). I would like to pass ColID as parameter.

following is my code snippet:

jQuery(document).ready(function () {
    jQuery("#list").jqGrid({
        //url: '/TabMaster/GetGridData',
        url: '/TabMaster/DynamicGridData',
        datatype: 'json',
        mtype: 'GET',
        colNames: ['col ID', 'First Name', 'Last Name'],
        colModel: [
            { name: 'colID', index: 'colID', width: 100, align: 'left' },
            { name: 'FirstName', index: 'FirstName', width: 150, align: 'left', editable: true },
            { name: 'LastName', index: 'LastName', width: 300, align: 'left', editable: true }
        ],
        pager: jQuery('#pager'),
        rowNum: 4,
        rowList: [1, 2, 4, 5, 10],
        sortname: 'colID',
        sortorder: "asc",
        viewrecords: true,
        gridview: true,
        multiselect: true,
        imgpath: '/scripts/themes/steel/images',
        caption: 'Tab Master Information'
    }).navGrid('#pager', { edit: true, add: true, del: true },
        //Edit Options
        {
        savekey: [true, 13],
        reloadAfterSubmit: true,
        jqModal: false,
        closeOnEscape: true,
        closeAfterEdit: true,
        url: "/TabMaster/Edit/",
        afterSubmit: function (response, postdata) {
            if (response.responseText == "Success") {
                jQuery("#success").show();
                jQuery("#success").html("Company successfully updated");
                jQuery("#success").fadeOut(6000);
                return [true, response.responseText]
            }
            else {
                return [false, response.responseText]
            }
        }
    });
});

here is i am getting JQRowIndex

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection updateExisting)
{
    TabMasterViewModel editExisting = new TabMasterViewModel();
    editExisting = _tabmasterService.GetSingle(x => x.colID == id);
    try
    {
        UpdateModel(editExisting);
        _tabmasterService.Update(editExisting);
        return Content("Success");
    }
    catch
    {
        return Content("Failure Message");
    }
}

Here is the logic to generate JSON response.
Method:1
*This is not display any record, even also dosen’t fire any exception*

 public JsonResult DynamicGridData(string OrderByColumn, string OrderType, int page, int pageSize)
    {
        int pageIndex = Convert.ToInt32(page) - 1;
        int totalRecords = GetTotalCount();
        int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
        IQueryable<TabMasterViewModel> tabmasters = _tabmasterService.GetQueryTabMasterList(OrderByColumn, OrderType, page, pageSize);
        var jsonData = new
        {
            total = totalPages,
            page = page,
            records = totalRecords,
            rows = (from tm in tabmasters
                    select new
                    {
                        id = tm.colID,
                        cell = new string[] { tm.colID.ToString(), tm.FirstName, tm.LastName }
                    }).ToArray()
        };
        return Json(jsonData, JsonRequestBehavior.AllowGet);
    }

The following is working perfectly. (this is working fine but i want to use Method:1 instead of Method:2)
Method:2

public ActionResult GetGridData(string sidx, string sord, int page, int rows)
        {
            return Content(JsonForJqgrid(GetDataTable(sidx, sord, page, rows), rows, GetTotalCount(), page), "application/json");
        }
        public int GetTotalCount()
        {
            return Convert.ToInt32(_tabmasterService.Count());
        }
        public DataTable GetDataTable(string OrderByColumn, string OrderType, int page, int pageSize)
        {
            TabMasterListViewModel models = _tabmasterService.GetTabMasterList(OrderByColumn, OrderType, pageSize, page);
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("colID", Type.GetType("System.Int32")));
            dt.Columns.Add(new DataColumn("FirstName", Type.GetType("System.String")));
            dt.Columns.Add(new DataColumn("LastName", Type.GetType("System.String")));
            foreach (TabMasterViewModel model in models.TabMasterList)
            {
                DataRow dr = dt.NewRow();
                dr[0] = model.colID;
                dr[1] = model.FirstName;
                dr[2] = model.LastName;
                dt.Rows.Add(dr);
            }
            var rows = dt.Rows.Count;
            return dt;
        }
        public static string JsonForJqgrid(DataTable dt, int pageSize, int totalRecords, int page)
        {
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
            StringBuilder jsonBuilder = new StringBuilder();
            jsonBuilder.Append("{");
            jsonBuilder.Append("\"total\":" + totalPages + ",\"page\":" + page + ",\"records\":" + (totalRecords) + ",\"rows\"");
            jsonBuilder.Append(":[");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                jsonBuilder.Append("{\"id\":" + dt.Rows[i][0].ToString() + ",\"cell\":[");
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    jsonBuilder.Append("\"");
                    jsonBuilder.Append(dt.Rows[i][j].ToString());
                    jsonBuilder.Append("\",");
                }
                jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
                jsonBuilder.Append("]},");
            }
            jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
            jsonBuilder.Append("]");
            jsonBuilder.Append("}");
            return jsonBuilder.ToString();
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:50:23+00:00Added an answer on May 23, 2026 at 4:50 am

    I suppose that the origin of your problem is wrong filling of JSON data in the GetGridData. Because your code contain imgpath I could suppose that you use some very old example of jqGrid. In some old examples it was a bug that one used i instead of id in the JSON data. If jqGrid don’t find id property in the input data it uses integers 1, 2 and so on as ids. I suppose it is your case. If you includes at least the last lines of your GetGridData we would see that.

    I recommend you to look at the UPDATED part of the answer and download the corresponding demo project. It shows not only how to implement data paging, sorting and filtering in ASP.NET MVC 2.0 but shows additionally how to use exceptions to return informations about an error from the ASP.NET MVC.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jqGrid on a page and users can click a button to
I have a jqGrid that has add/edit dialogs with a form that's longer than
I have a jqGrid with multiselect:true. In a click event of a button I
I'm using the JQGrid and have an Add new button defined. $(gridId).jqGrid('navButtonAdd', pagerId, {
I am trying to customize the delete function in jqGrid. I have enabled the
I have a jqGrid where the View icon is enabled (view:true), so that a
I have a jqGrid with which users will select records. A large number of
I have this mysql tables I want to display with jqgrid. The problem appears
I am using jqgrid and have simple searching enabled. I am wondering if there
I have jqgrid and in that I have one custom navigation button to export

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.