I am posting table with dynamically added data to the controller action.
On the UI there is a form field to search Terms which are already added to the DB. User just search and add them to the table with a single click.
To post this table data to the action I am doing these steps:
Step 1: Create array TermsData and fill it with the required data of the table.
var TermsData = [];
var dataRows = oTNCTable.rows().data();
for (var i = 0; i < dataRows.length; i++) {
TermsData.push({
Name: dataRows.cell(i, 1).data(),
DisplayName: dataRows.cell(i, 2).data(),
Description: dataRows.cell(i, 3).data(),
});
}
Step 2: Convert this array to the json string.
var jsonTerms = JSON.stringify(TermsData);
Step 3: Add this json string to the form hidden field
$("#JsonTerms").val(jsonTerms);
Step 4: On the Action of the controller I am deserializing this string using model.
var QuoteTerms = JsonConvert.DeserializeObject<List<TermsConditionsList>>(model.JsonTerms);
model.QuoteTermsConditions = QuoteTerms;
then processing this data.
its working fine until I have this issue:
When the user entered '&' symbol in the data, I am receiving html as & in the action but I need '&' only to do processing.
So my questions are:
- Is it a good approach to get the Jquery DataTable dynamically added data to the action?
- If not then what should be the best approach?
- What should I do to convert & back to the & symbol?
I just need all data to action as it is because user fetching data to the UI and then just adding it to the table and submitting it.