How to pass parent id to child view representation view

I am new to MVC2 and my question should be pretty simple. At least I thought so until I find any answer on the Internet, so I'm here.

I have a parent object pool that can hold from 0 to many children.

In my detailed Pool view, in addition to the Pool property, I am making it childs using RenderAction in the Question action list, so far so good.

Inside my view of the list of questions (which is always displayed inside the Details view), I want the button to start the Create action of the Question object. My problem is that I don’t know how to pass the Pool object, which is the model of my detailed view, to the Create action in order to associate my question with the correct pool.

Is there a way to access the "Master Model" inside the "included" view through RenderAction, and if not, what is the best way to implement the work.

thank

0
source share
2 answers

This is one of my favorite hidden stones in MVC .. it will give you the parent model:

<% object parentModel = ViewContext.ParentActionViewContext.ViewData.Model; %>
+1
source

clicktricity , Html.Action. docOrdinal , .

[ChildActionOnly]
public ActionResult ActiveDocumentsDegree(string docOrdinal) 
{
    var model = (UserModel)ControllerContext.ParentActionViewContext.ViewData.Model;
    .
    .
    .
}
0

Source: https://habr.com/ru/post/1779100/