'Dynamic populate dropdown for Sweetalert2
I am trying to populate a dropdown option for a SweetAlert alert by passing an array or string list from my MVC controller to view.
I can get the values to populate in the dropdown but when the text is selected it only returns the value such as 0 and will not return the text. Which is meaningless.
I have tried passing it in a two-dimensional array so I was setting the value and text but that didn't display right. I have also tried passing a directory but I was not able to get that to parse in my Jquery.
Sorry if this is something very obvious.
var inputOptionsPromise = obj.Attatchments;
alert(inputOptionsPromise);
Swal.fire({
title: 'Select Attatchment for Upload',
input: 'select',
inputOptions: inputOptionsPromise,
inputPlaceholder: 'Select an attatchment',
showCancelButton: true,
inputValidator: (value) => {
return new Promise(function (resolve, reject) {
if (value !== '') {
resolve();
} else {
resolve('Select an attatchment');
}
});
}
}).then(function (result) {
if (result.isConfirmed) {
// trying to get text value
alert(result.value);
alert(result.text);
alert(result);
}
});
//Controller
string[,] array2D = new string[,] { { "text.pdf","text.pdf"}, { "test.txt", "test.txt" } };
//string[] array = new string[] { "text.pdf", "test.txt" };
return Json(JsonConvert.SerializeObject(new { Success = false, File = fileStream, Attatchments = array2D , ErrorMessage = "" }), JsonRequestBehavior.AllowGet);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
