I have a HTML dropdownList which currently showing data from model, Now for some operations I want to change the dropdownList content. I guess If I update model it will reflect to view also. Below is my code for Model
ViewModel
public class CaseAssignmentRuleSetViewModel
{
public CaseAssignmentRuleSetViewModel()
{
}
public int id { get; set; }
public string name { get; set; }
public Dictionary<string, string> AssignmentUsers { get; set; }
}
So here in viewModel its a dictionary which is source for dropdownList in view which looks like below.
View
<select name="assignmentTeam" class="form-control case-assignment-use-type-value2" placeholder="Select a User">
@foreach (string key in Model.AssignmentUsers.Keys)
{
<option value="@key">@Model.AssignmentUsers[key]</option>
}
</select>
and finally after some operations I am getting new list returned using JQuery function to my Controller method which looks like below.
Controller
[HttpPost, Route("CaseAssignmentRuleSet/ListofAssignees", Name = "ListofAssignees")]
public List<string> SetListofAssignees(string [] listOfAssignedroles)
{
CaseAssignmentRuleViewModel caseAssignmentRuleViewModel = new CaseAssignmentRuleViewModel();
List<string> listOfAssignees = new List<string>();
if (listOfAssignedroles!= null)
{
listOfAssignees = new List<string>(listOfAssignedroles);
}
return listOfAssignees;
}
How can I update my dropdownList in view with new list of items?