开发者

ASP.NET MVC jQuery Ajax

I want to create a grid like gmail's where the user can d开发者_StackOverflow社区elete or update via actions (eg assigning label in gmail) via jQuery and ajax.

I have implemented the ajax calls so its sets the data to correct values in DB, but what is the best practice for updating the grid/row without having to refresh the page?


The simplest option is to put the grid into a partial view, then send an AJAX request every 30 seconds (or so) that dumps the partial view's HTML into the DOM.

It would be more efficient to download a list of changes as JSON, then update the DOM using Javascript.
To download a list of changes, you'll need to keep track of the current state on the server.
Depending on your data, that might not be practical.


There are several ways of doing this, personally I like the MVVM pattern for things like this. There is a great library called knockoutjs which allows for binding to a javascript object model. Here is an example of an editable grid to get you started. This in my opinion is the most flexible way of working with the web as it separates your concerns. HTML/Javascript at this point becomes resposible for your UI only while the ASP.NET MVC takes care of your business logic and sends down the ViewModel.

You could also use a jQuery plugin solution such as jqGrid, you will still need to code all your CRUD functions to actually manager the data, but the gird will auto allow for sorting (with some configuration) and other options. This will also handle your CSS formatting as it users the jQuery UI for styling.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜