Mvc DropDownListFor not showing selected value

Hello, I have a dropdownlist that I am populating for a plugin I'm working on. When I create a "New" entry with blank fields the Dropdown List is not Selecting based on the ID passed through the url, even though it is set to "select".

Here is my DropDown code:


var fundraiserOrganizations = _fundraiserService.GetFundraiserOrganizations[];
model.AvailableFundraisers.Add[new SelectListItem[] { Text = "---", Value = "0" }];
foreach [var tc in fundraiserOrganizations]
{
if [fundraiserParticipent == null]
{
model.AvailableFundraisers.Add[new SelectListItem[] { Text = tc.FundraiserName, Value = tc.Id.ToString[], Selected = tc.Id == organizationId }];
}
else
{
model.AvailableFundraisers.Add[new SelectListItem[] { Text = tc.FundraiserName, Value = tc.Id.ToString[], Selected = tc.Id == fundraiserParticipent.FK_FundraiserID }];
}

}

Where "organizationId" is the "ID" passed through the URL.

Here is my View code:



@Html.DropDownListFor[model => model.FK_FundraiserID, Model.AvailableFundraisers, new { @disabled = "disabled" }]

Here is a screenshot of my "Model" as it is being returned in the View:
www.ochapparel.com/Content/Images/uploaded/model.png

Now if I already have a participant, then and i'm editing them. Then the dropdown list selects the right one....

Any help is appreciated.

Video liên quan

Chủ Đề