In handling a 1—>0…1 relationship, I’m trying to use a separate partial view for the 0…1 end. I’d like to use RenderPartial() rather than RenderAction(), for the sake of efficiency.
Is it possible to gain access to the containing view’s model data from this partial view, in order to access the PK/ID of the main object?
Is this just a sad attempt at a hack that shouldn’t even be considered in the first place?
Does anyone have a better example of how to handle this 1—>0…1 relationship using MVC?
Sort of.
If you don’t pass a model to
RenderPartial, the parent’s view is passed by default. So you can access it via the partial’sModelproperty.But if you do pass a model, then no, the partial can’t see the parent’s model, because it sees its own instead.
I’d say “kludge” rather than “hack”, but yes, probably. 🙂