This is a follow up to MVC3 form in partial view
Although the author gave a workaround to the problem. I would like to find out a proper answer why this is not working.
I don't have access to original code, but here's mine (so I can answer following questions):
// main view (which is partial too)
@foreach (AddingComponentVM sc in Model)
{
@Html.Partial("_SearchIngredientUpdate", sc);
}
//partial view
@using (Ajax.BeginForm("IngredientSearchUpdate", new { controller = "Recipe" }, ajxOpt, new { id = "addingWidgetForm" + Model.IngredientID }))
{
@Html.TextBoxFor(model => model.IngredientID)
@Model.IngredientID
}
@Model.IngredientID contains proper value. But the textbox contains value of the model sent to controller (sic!) and it is obviously the same for each form.
[AjaxOnly]
public JsonResult IngredientSearchUpdate(
AddingComponentVM dataIn,
[ModelBinder(typeof(SearchOptionsBinder))] SearchOptions sessionSO)
If action without AddingComponentVM in signature calls the same code above, forms renders correctly.
public PartialViewResult IngredientSearch([ModelBinder(typeof(SearchOptionsBinder))] SearchOptions sessionSO)
Anyone could point me out to the cause of this strange (at least for me) behaviour? Thanks!