开发者

How to refresh grid after ajax call in asp.net mvc?

HI, I have a asp.net mvc grid with delete and edit button. when i click on delete button i need to delete the data and refresh the grid. for this 开发者_StackOverflowi am making an ajax call which deletes the data, but not ablet o refresh the grid. How can i achieve this?


When you say grid is this just a basic table that you've added delete and edit button to, or is it a grid control by someone?

If it's just a table then what you probably need to do is remove the row you've deleted using javascript (which will be made much easier with something like jQuery).

Another approach would be to use something like jqGrid which handles a lot of that for you. Although it can take a little while to get up and running, in my experience it's normally worthwhile.


There is a callback for the Ajax helpers in MVC "OnSuccess", you could remove the row using this callback, The success callback, as well as any other callbacks you can specify in the AjaxOptions object, receives only one argument of type AjaxContext. Heres a breakdown of the callback function javascript object properties.

example callback

function OnSuccess(context){
... do stuff here
}

get_data Gets any data returned from the controller action.

get_insertionMode Indicates how to treat the response (only if markup), whether to replace, prepend, or append it to the markup of the specified DOM element. The default is replace.

get_loadingElement Indicates the DOM element to be displayed to indicate that an AJAX call is going on.

get_request Gets the Sys.Net.WebRequest object that represents the current request.

get_response Gets the Sys.Net.WebRequestExecutor object for the current request.

get_updateTarget Indicates the DOM element to be automatically updated with the returned markup, if any.

This should be everything you need inorder to perform your edit/delete.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜