I have the following on my edit screen:
<label for="campaign.CandidateID">Candidate:</label>
<%= Html.DropDownList("Campaign.CandidateID", Model.Candidates, "Choose...")%>
<%= Html.ValidationMessage("CandidateID", "*") %>
and in my controller:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection formValues)
{
Campaign campaign = repos.GetCampaign(id);
try
{
UpdateModel(campaign);
repos.Save();
return RedirectToAction("Index", "Admin");
}
catch
{
return View(new CampaignDTO(campaign));
}
When I edit the record and change text fields, everything works perfectly, but when I change an item connected to a dropdownlist, the change does not get updated in the campaign object. I have checked this.ValueProvider["Campaign.CandidateID"]
and the data is in there!
By the way, during the display of the edit screen, it is selecting the correct Candidate in the select list.
Could the problem come from the fact that ValueProvider is providing a string whereas CandidateID in my class is an int?
I'm stumped.