Santhosh
Santhosh

Reputation: 20426

MVC 2 RenderAction

Im having a value in ViewData, lets say htmlhelper.ViewData["myData"]="some";

And in partial page I can overwrite the myData's value.

But when I using the Html.RenderAction() and call a partial page.

In the same partial page htmlhelper.ViewData["myData"] is null.

Upvotes: 2

Views: 711

Answers (2)

Santhosh
Santhosh

Reputation: 20426

I figured out from MVC source code. Cool that we have MVC as open source.

htmlHelper.ViewContext.HttpContext.Items["myData"]

this will maintain the value from Partial and RenderAction case.

Upvotes: 0

Andrew
Andrew

Reputation: 1775

When you call RenderAction, you create an entirely new ViewData instance for your partial page. If you want ViewData["myData"] to be visible by your other action, either pass it to the subaction or put it in TempData.

Upvotes: 3

Related Questions