Post data to the action result in jqGrid and ASP.NET MVC

Below example shows how to postdata from the jQGrid to ASP.NET MVC ActionResut when dropdown change

Script


$(".selectRequestType").change(function () {
$('#jqgRequests').setGridParam({ postData: { FilterValue: $(this).val() } }).trigger('reloadGrid', [{ page: 1 }]);
});

Action Result


[AcceptVerbs(HttpVerbs.Post)]
public JsonResult LoadRequest(JqGridRequest request, PostDataViewModel postData)
{
}

public class PostDataViewModel
{
public string FilterValue { get; set; }
}

One thought on “Post data to the action result in jqGrid and ASP.NET MVC

  1. hii , i’m using JqGrid first time , can you help me ,
    try to add a new row , how can we post data to a controller method by a ajax call.

    this examle is not working for me.

    public JsonResult AddUserDetails()
    {

    …..
    }

    jQuery(“#jQGridDemo”).jqGrid({
    url: ‘/Admin/GetUserDetails/’,
    datatype: “json”,
    colNames: [‘Id’,’UserName’,’Password’,’FirstName’,’LastName’],
    colModel: [
    { name: ‘UserId’, index: ‘Id’, width: 100, stype: ‘text’ },
    { name: ‘UserName’, index: ‘UserName’, width: 150, stype: ‘text’, sortable: true, editable: true },
    { name: ‘Password’, index: ‘Password’, width: 150, stype: ‘text’, editable: true },
    { name: ‘FirstName’, index: ‘FirstName’, width: 150, stype: ‘text’, editable: true },
    { name: ‘LastName’, index: ‘LastName’, width: 150, stype: ‘text’, editable: true },

    ],
    rowNum: 10,
    mtype: ‘GET’,
    loadonce: true,
    rowList: [10, 20, 30],
    pager: ‘#jQGridDemoPager’,
    sortname: ‘_id’,
    viewrecords: true,
    sortorder: ‘desc’,
    caption: “List Employee Details”,
    //addurl: ‘/Admin/AddUserDetails/’,

    });
    $(‘#jQGridDemo’).jqGrid(‘navGrid’, ‘#jQGridDemoPager’,
    {
    edit: true,
    add: true,
    del: true,
    search: true,
    searchtext: “Search”,
    addtext: “Add”,
    edittext: “Edit”,
    deltext: “Delete”
    },
    {
    width: ‘auto’, url: ‘/Admin/EditCounterPart/’
    },
    {
    width: ‘auto’,
    url: ‘/Admin/AddUserDetails/’,

    },
    { url: ‘/Admin/DeleteCounterPart/’ },
    {//SEARCH
    closeOnEscape: true

    }
    );

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s