child-actions

How can I tell if my action is being called by RenderAction?

旧街凉风 提交于 2019-12-04 18:14:20
问题 I have an action that could potentially be called via a normal link, in which case I'd return a View(), or it could also be called via AJAX or RenderAction (ie as a Child Action) in which case I'd return a PartialView(). Sorting out the AJAX part is easy - but how can I test if my action is being rendered as a Child Action? Ideally, I'd like to be able to write code like this: if (Request.IsAjaxRequest() || Request.IsChildAction()) return PartialView(); return View(); Obviously the Request

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

被刻印的时光 ゝ 提交于 2019-11-27 21:04:20
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 same controller. and I need the Child action and the Parent action to share some data in the ViewBag.Now ,what I should do ?Here is my question: when I call the Child action in parent's view file ,I pass the viewbag to it like this: @Html.Action(ViewBag). in my child action ,I do this: public PartialViewResult Child(Object ViewBag) { //using the data in ViewBag } Is this the right way ? Does the viewbag object passed by

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

时光毁灭记忆、已成空白 提交于 2019-11-27 04:29:07
问题 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 same controller. and I need the Child action and the Parent action to share some data in the ViewBag.Now ,what I should do ?Here is my question: when I call the Child action in parent's view file ,I pass the viewbag to it like this: @Html.Action(ViewBag). in my child action ,I do this: public PartialViewResult Child(Object