Post table data to action which is dynamically add

2019-03-04 14:34发布

问题:

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 &amp in the action but I need '&' only to do processing.

So my questions are:

  1. Is it a good approach to get the Jquery DataTable dynamically added data to the action?
  2. If not then what should be the best approach?
  3. What should I do to convert &amp 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.