2

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.

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

how to pass it to the subaction ?
The same as if you were calling another action from the view ... Something like: Html.RenderAction("SomeAction", new { id = 1, param2 = "something, param3 = "something else" })
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.