开发者

MVC 2 RenderAction

开发者 https://www.devze.com 2022-12-17 21:15 出处:网络
Im having a value in ViewData, lets say htmlhelper.ViewData[\"myData\"]=\"some\"; And in partial page I can overwrite the myData\'s value.

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 part开发者_开发技巧ial page htmlhelper.ViewData["myData"] is null.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消