I have a strongly typed partial view whose model contains a property with the same name as the view model of the parent page. For some reason, the rendering engine displays the value of the parent view model, rather than the expected value (well, the value that I expect at least!)
Instance of the source page view model:
public class ParentPageViewModel { public int Id { get; set; }
Extract of the child page view model:
public class ChildViewModel { public int Id { get; set; }
Parent Page Instance (Razor):
@model ParentPageViewModel ... @foreach (var item in Model.Children) { @Html.Partial("MyPartialView", item) } ...
Partial View Instance:
@model ChildViewModel ... <form ...> @Html.HiddenFor(m => m.Id) // problem here - get ParentPageViewModel.ID not ChildViewModel.Id </form> ...
So basically in my visualized release, my hidden field has the value of the model element of the parent view, and not the value passed to the partial view. This is definitely caused by the name, since changing the name of @ ChildViewModel.Id @ to something like @ ChildViewModel.ChildId @ makes it work properly. Interestingly, when checking the values ββof the view model in the debugger, I see the correct values; this is only processed output that is erroneous.
Is there a way around this or the βrightβ way to do what I'm trying to do (I process mini forms in the table to check ajax / post updates in the rows of the table)
Thanks,
Tim
source share