I have a Partial View with a DropDownListFor-Element.
Partial View
@model Person
<h4>Show me OrganizationID: @Model.Organization_ID</h4>
@Html.DropDownListFor(model => model.Organization_ID, new SelectList(ViewBag.AllOrganizations, "ID", "Name"))
Now when updating the Partial View via JQuery and change the "Organization_ID" of the model in the controllers action method, the selected item of DropDownListFor will be not changed after update, even though the organization exists in the DropDownList!
JQuery (in Create.cshtml)
var url = '@Html.Raw(Url.Action("ReloadPerson", "Home"))';
$('#divPerson').load(url, $('#formPerson').serializeArray());
Controller
public ActionResult ReloadPerson([Bind(Include = "ID, [...], Organization_ID")] Person person)
{
ViewBag.AllOrganizations = _ecmManager.GetAllOrganizations ();
person.Organisation_ID = (Guid)TempData["Organization_ID"];
return PartialView("Person", person);
}
The action method puts via TempData a new ID in the property of my object and send it back to the Partial View model. The h4-header shows me after updating the new organization-id, but my DropDownListFor-Element doesn't select the organization he get from the model.
The functionality of DropDownListFor is tested:
public ActionResult Create()
{
ViewBag.AllOrganizations = _ecmManager.GetAllOrganisationen();
return View(new Person() { Organization_ID = _ecmManager.GetOrganizationByID(new Guid("E2A9C501-1E53-4074-9B4B-04C693FB753A")).ID });
}
I've tested the functionality, when loading my View with an explicit model and it works how it should. The dropdownlistfor auto-selected the organization from its modelbinding.
So, how can I update my DropDownListFor-Element after Partial View Update (no reloading of the whole page via JQuery)?