I'd appreciate if someone could advise on the following: I invoke my controller ActionResult passing some string and then I get the data. How can I use this data to populate my DropDownList and show it to user?
$.ajax({
type: "POST",
url: '@Url.Action("Action","Controller")',
data: { passedString: "Industrial"},
success: function(data){
//pass data to ViewBag??
}
});
my view:
@Html.DropDownListFor(model => model.TraumaCode, (SelectList)ViewBag.TraumaList)
my controller action:
public ActionResult GetTraumaType(string passedString)
{
if (passedString == "Industrial")
{
ViewBag.TraumaList = some Value...
}
else
{
ViewBag.TraumaList = another Value...
}
}
I understand I cannot change the ViewBag info, because the page is loaded once, is there another way to pass data to DropDownList?