DataTables breaks dotnet core Razor Model Binding
DataTables breaks dotnet core Razor Model Binding
I've been working with DataTables for a couple of weeks and it's been great for a project I inherited.
The project is based on DotNetCore 6 with Razor MVC pages and jQuery.
I've updated a couple of places in the app that had static html tables to using DataTables and the search and sorting have been very useful.
I just recently hit a snag on a page that has controls inside the table footer and uses Razor's Model Binding to deliver user interactions to an endpoint when the form is submitted to perform some tasks.
I have found that when I implemented the DataTable, the model object is empty when it goes to the endpoint, ignoring the users interaction with multiple selects. If I disable the DataTable javascript and return to a plain html table, the model binding works again and the model object has data in it.
This is an internal application so I cannot link to it.
I saw mention of a legacy ajax compatibility mode that might be a potential fix but I'm not sure how to implement that.
Does anyone have a good approach to fixing or at least troubleshooting this? There are no errors at the front end, just the back end because of the lack of data (as if no selections have been made).
Thanks!
Answers
There is no test case provided, so I can't debug it I'm afraid.
There is nothing that immediately springs to mind, but I'm no expert in Razor. I'd wondered if they might be trying to control the same DOM elements, which would be bad news, but I'm not certain that is the case. You talk specifically about
select
elements, and DataTables won't create or modify those. It might move them around the DOM, and perhaps that is enough to break the binding, but I don't know.Allan
Ok, thanks. I'll keep digging. I appreciate the response.