Reputation: 4126
i need to have a send button in my jqgrid. So it means that i have to call An action from my controller when im pressing on the button. Ive got the code for my delete button. but i cant figure out how to send additional data with my action :
gridComplete: function () {
var gr = jQuery('#list'); gr.setGridHeight("auto", true);
var ids = jQuery("#list").jqGrid('getDataIDs');
for (var i = 0; i < ids.length; i++) {
var cl = ids[i];
be = "<a href='#' style='height:25px;width:120px;' type='button' value='Slet' onclick=\"jQuery('#list').jqGrid('" + cl + "', @Url.Action("Action")); return false;\">Send</>";
jQuery("#list").jqGrid('setRowData', ids[i], { act: be });
}
},
Upvotes: 1
Views: 1347
Reputation: 5893
(Answered in a question edit and comments. Converted to a community wiki answer. See What is the appropriate action when the answer to a question is added to the question itself? )
The OP wrote:
Solved this one by using ajax request
var Send = function (rowId) { $.ajax({ mtype: "POST", url: '@Url.Action("Action")', data: { actionparameter: rowId }, async: false, cache: false }); }; gridComplete: function () { var gr = jQuery('#list'); gr.setGridHeight("auto", true); var ids = jQuery("#list").jqGrid('getDataIDs'); for (var i = 0; i < ids.length; i++) { var cl = ids[i]; var be = "<a href='#' value='Slet' onclick=\Send(" +cl + "); return false;\">Send</>"; jQuery("#list").jqGrid('setRowData', ids[i], { act: be }); } },
@Oleg wrote:
You should only
- remove
async: false
which is not needed.- remove
cache: false
because you use "POST" which is not cached.- replace
mtype: "POST"
to type: "POST"- replace '=\Send(' to '=\"Send('
You send currently only
rowId
to the server and no data.You did't post the whole grid, so I don't know whether you made local grid editing and the modified data should be send additionally. If you look at the documentation of
$.ajax
you will find parameter type which default value is "GET". If you writemtype: "POST"
it will be ignored likeblabla: "HaHa"
. So theHTTP GET
request will be sent wherecache: false
can have sense, but "POST" could be not allowed in the Action. What you really want wastype: "POST"
. By the way I recommend you to include in your question better too much code as to few. Many things could be more clear and all will save there time
Upvotes: 1