jqGrid
$(document).ready(function () {
$("#grid").jqGrid({
url: '@Url.Action("GetAllAuthors", "Admin")',
datatype: "json",
mtype: 'get',
colNames: ['Yazar Adı', 'Öz Geçmiş'],
colModel: [
{ name: 'Name', index: 'Name', editable: false },
{ name: 'Description', index: 'Description', editable: false }
],
jsonReader: {
repeatitems: false,
id: "sno",
root: "rows", //array containing actual data
page: "page", //current page
total: "total", //total pages for the query
records: "records", //total number of records
repeatitems: false
},
rowNum: 10,
rowList: [10, 20, 30, 40, 50],
pager: jQuery('#gridpager'),
sortname: 'Name',
viewrecords: true,
sortorder: "asc",
width: 710,
height: 300
})
.navGrid('#gridpager', { edit: false, add: false, del: false, search: false, refresh: false })
.navButtonAdd('#gridpager', {
caption: "Düzenle",
buttonicon: "ui-icon-pencil",
onClickButton: function () {
var grid = $("#grid");
var rowid = grid.jqGrid('getGridParam', 'selrow');
//alert(rowid + " - " + grid.jqGrid('getCell', rowid, 'CustomerName') + " - Link: " + $("#customers_grid_table a.customer_details").attr("href"));
window.location = '@Url.Action("EditAuthor", "Admin")?authorId=' + rowid;
//LoadAction('@Url.Action("EditAuthor", "Admin")?authorId=' + rowid);
}
}); //end jqgrid
});
I have two method in my controller
Get method
[HttpGet]
public ActionResult EditAuthor(int authorId)
Post method
[HttpPost]
public ActionResult EditAuthor(AuthorViewModel model, HttpPostedFileBase file)
I selected a row and clicked edit button, I expect to fire get method, but post method is fired. What can I do to fire get method?
Thanks.
If you set new value of
window.locationthe HTTP GET will be used. To produce HTTP POST you can either use$.ajaxor submit some form. You can for example dynamically build invisible<form>and submit it. For exampleI recommend you additionally to include additional validation whether some row is selected (whether
rowidis not null).Moreover I recommend you
gridview: trueoption in the grid which will just improve the performance of the grid.pager: jQuery('#gridpager')topager: '#gridpager'.jsonReaderoption tojsonReader: {repeatitems: false, id: "sno"}. The options which you specify will be combined with default value (see the documentation). Additionally your current value ofjsonReaderoption contains syntax error because you specify the same propertyrepeatitems: falsetwice.