Hello
I am trying to pass back an editable HTML table back to my controller.To do this I have wrapped my table in a form and used a serializeArray() to pass the data to the controller.
However, my data object now looks like the following
[
{
"name": "[0].blnApprove",
"value": "false"
},
{
"name": "[0].blnRejected",
"value": "false"
},
{
"name": "[0].RejectReason",
"value": ""
},
{
"name": "[0].autHolidayRequestID",
"value": "61"
},
{
"name": "[1].blnApprove",
"value": "true"
},
{
"name": "[1].blnRejected",
"value": "false"
},
{
"name": "[1].RejectReason",
"value": ""
},
{
"name": "[1].autHolidayRequestID",
"value": "172"
},
{
"name": "[2].blnApprove",
"value": "false"
},
{
"name": "[2].blnRejected",
"value": "true"
},
{
"name": "[2].RejectReason",
"value": "Absences"
},
{
"name": "[2].autHolidayRequestID",
"value": "173"
}
]
which is not usable. Ideally, id like to be able to get the data in the following format.
List<Holidays> holiday = new List<Holidays>
{
new Holidays{ autHolidayRequestID=61, blnApprove="false", blnRejected="false", RejectReason="" },
new Holidays{ autHolidayRequestID=172, blnApprove="true", blnRejected="false", RejectReason="" },
new Holidays{ autHolidayRequestID=173, blnApprove="false", blnRejected="true", RejectReason="Absences" },
};
I was thinking I could use a 3-dimensional array like the below and then loop through my code however I'm not able to recreate this in javascript or jquery. I also suspect I'm starting to over complicate things ?
holidays[0][autHolidayRequestID][61]
holidays[0][blnApprove][false]
holidays[0][blnRejected][false]
holidays[0][RejectReason][""]
holidays[1][autHolidayRequestID][61]
holidays[1][blnApprove][true]
holidays[1][blnRejected][false]
holidays[1][RejectReason][""]
holidays[2][autHolidayRequestID][61]
holidays[2][blnApprove][false]
holidays[2][blnRejected][true]
holidays[2][RejectReason]["Absences"]
Could someone please offer some advice on the best way to handle this ?
What I have tried:
wrapped my table in a form and used a serializeArray() to pass the data to the controller.