DataTables Server-Side Processing - MVC Model attribute loses value

DataTables Server-Side Processing - MVC Model attribute loses value

rgl928rgl928 Posts: 7Questions: 0Answers: 0
edited February 2014 in General
I'm using data tables plugin to show info, but there is a column with an text input for each row that is supposed to bind to a model attribute. I'm using Server-Side processing approach.

I've got a Model class name Donation and one of its attributes is:

[code]public int protocolNumber {get; set;}[/code]

There's a view model whith a [code]List donations[/code] attribute, with is filled in the controller. And the view is strongly typed to the view model.

As I'm using server side processing, I generate the text input by writing the html in the controller method that responses to the ajax call like this:

[code][/code]

Where every input id and name will depend on the display number, so there will be number 1,2,3, etc.

When the table draws I put values for the input in the first page, and when I submit the List goes to server with values, but if I use pagination, when I put values on the fields the list is null when I do the postback.

For some reason it seems that when the table re-draws calling the ajax again, it loses the binding to the model.

Any help would be appreciated! Thanks!

Replies

  • rgl928rgl928 Posts: 7Questions: 0Answers: 0
    I realized what was wrong. I live the answer here for future reference. I was generating different names for each text input depending on the pages. For example, if I am displaying 10 rows, names for page 1 will be `donations[0],donations[1],...,donations[9]` for the page 2
    will be `donations[10],donations[11],...,donations[19]`. The problem is that with server side processing after each ajax call the table redraws, and you lose the previous elements with name from `0,1... to 9` so you only have now the ones that goes from `10,11... to 19` and mvc can't return a list that have elements starting in an index different from 0. That's why it wasn't working.
This discussion has been closed.