I'm having a problem displaying selected value with Html.DropDownListFor. I have a view that uses multiple drop downs, all of them get populated, but nothing gets selected. I have same selection choices for every dropdown, but different selected values. Here's my viewmodel:
public class ViewPersonTargetingViewModel
{
public List<PersonTarget> Targets { get; set; }
public SelectList TargetStatuses { get; set; }
}
That's how I make a SelectList:
var statuses = DataAccess.GetPersonTargetStatuses();
TargetStatuses = new SelectList(statuses, "PersonTargetStatusUuid", "PersonTargetStatusName");
My PersonTarget class:
public class PersonTarget
{
public string PersonTargetStatusName { get; set; }
public Guid PersonTargetStatusUuid { get; set; }
//and more
}
And this is how I create a DropDownList:
<%: Html.DropDownListFor(model => model.Targets[k].PersonTargetStatusUuid, Model.TargetStatuses)%>
where k is an iteration through Targets List.
I use the same SelectList to populate all of the DropDowns, it contains info like this:
- Text: A Value: b2e4a939-06d8-4052-8abf-5c1b2a5e8591
- Text: B Value: 0b59faaa-514d-4212-93cd-6b0a50b8f151
- Text: C Value: 5575f3cf-33f8-41df-be73-a176a3db5ed5
for example, when I'm trying to get it to display "B", I give him the correct target status, but it still shows first element ("A") as selected, I even printed out the values I give him, and I get that Model.Targets[k].PersonTargetStatusUuid has the value of: 0b59faaa-514d-4212-93cd-6b0a50b8f151 (It's Guid of "B"), but it still displays "A". I ran out of ideas how to fix this. Any help is greatly appreciated, thanks :).