I'm having a element that called scanned-result that is having a list of barcodes, after I get all the codes I'm using the querySelectorAll from the elements I'm saving it in a String Array and then I send this list into the controller.
What can I do to send this array parameter urlParameter as a Post Method instead of use window.location.href to the controller?
When I start scanning the barcodes will save in results.innerHTML
function startScanning(facingMode) {
console.log(facingMode)
var results = document.getElementById('scanned-result');
function onScanSuccess(qrCodeMessage) {
if (lastMessage !== qrCodeMessage) {
lastMessage = qrCodeMessage;
++codesFound;
results.innerHTML += `<div> ${qrCodeMessage}</div>`;
}
}
When stop scanning I'm going to get the array looking by the element scanned-result sending the array to the controller, Here is when I'm stuck I'm not sure what I need to change to make it to send the parameter as a Post Method
function stopScanning() {
var QRCodeval = document.querySelectorAll("#scanned-result>div");
var arr = [];
QRCodeval.forEach((el) => arr.push(el.innerHTML));
let urlParams = arr.map((val) => {
return `arr=${encodeURIComponent(val)}`
}).join('&');
window.location.href = "@Url.Action("ReceivedFromBarCode", "PurchaseOrder")?arr" + urlParams;
}
In the View is going to appear the values on id="scanned-result"
<div class="modal-footer">
<div id="scanned-result"">
</div>
Controller
[HttpPost]
public async Task<ActionResult> ReceivedFromBarCode(string[] arr)
{
try
{
}
return RedirectToAction($"Details");
}
catch (VTHIS.CommunicationException cex)
{
throw cex;
}
}