Does a child action share the same ViewBag with its “parents” action?

前端 未结 2 1862
灰色年华
灰色年华 2020-12-05 17:13

I am confused with this: I have an action ,say Parent ,and in the corresponding view file ,I have called a child action ,say Child ,both Parent and Child actions are in the

2条回答
  •  不知归路
    2020-12-05 18:00

    Child actions follow a different controller/model/view lifecycle than parent actions. As a result they do not share ViewData/ViewBag. If you want to pass parameters to a child action from the parent you could do this:

    @Html.Action("Child", new { message = ViewBag.Message })
    

    and in the child action:

    public ActionResult Child(string message)
    {
        ...
    }
    

提交回复
热议问题