Passing ViewData to PartialView returned from using Html.Action

Posted by RWGodfrey on Stack Overflow See other posts from Stack Overflow or by RWGodfrey
Published on 2010-05-05T13:53:44Z Indexed on 2010/05/05 13:58 UTC
Read the original article Hit count: 290

I want to embed a partial view in an ASP.NET MVC page by returning it from an action method.

In my base view, I would have:

<%= Html.Action("MyPartialViewAction") %>

My controller would have an action method like:

[ChildActionOnly]
public ActionResult MyPartialViewAction()
{
    return PartialView("MyPartialView");
}

I expected the returned partial view (MyPartialView) to have access to the ViewData that was set in the base page's controller action but that doesn't appear to be the case. If I insert the partial view by using the following in my base view it works:

<% Html.RenderPartial("MyPartialView") %>

I don't want to do that though because I want my "MyPartialViewAction" to execute logic to determine WHICH partial view to return.

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2

Related posts about partial-views