Below is some example JSON data
https://i.sstatic.net/zl3XR.png
At the moment, I am successfully able to retrieve Bank HooMan
by using
var b = details.b.Select(x => x.Bank).FirstOrDefault();
when I put a breakpoint in the controller. However, my issue lies in how to select Hooman for @Html.DropDownListFor
Here is what I have attempted so far:
@Html.DropDownListFor(m => m.BankID, new SelectList(ViewBag.BankList, "BankID", "BankName", Model.b.Select(x => x.Bank).FirstOrDefault()), new { @class = "form-control" })
Unfortunately, this method does not seem to select HooMan. I have also tried utilizing SelectList
on the model like this:
details.BankList = new SelectList(JsonConvert.DeserializeObject<List<BankLists>>(await OperationServices.GetBankListAsync()),
"BankID", "BankName", details.b.Select(x => x.Bank).FirstOrDefault());
//View
@Html.DropDownListFor(m => m.BankID, Model.BankList, new { htmlAttributes = new { @class = "form-control" } })
However, I still encounter the same issue where the dropdownlist is unable to select the data. Is there something that I may be overlooking? Additionally, I need to access values within acs
.
EDIT (as requested by Tomato32):
BankList
is also in JSON format which we deserialize into a model. I can populate the list and add it to the dropdown, but I am struggling to select the value from the nested JSON mentioned above.