Can't access ViewBag in a partial view in ASP.NET MVC3

后端 未结 8 1406
无人共我
无人共我 2020-12-08 06:32

I have a controller calling a view. In the view there is a PartialView called be @Html.Partial(\"ViewName\", model). This works fine.

But i

8条回答
  •  独厮守ぢ
    2020-12-08 06:39

    If you are using an overload of the Html.Partial() where viewData is one of the input parameters, for example:

    @Html.Partial("PartialViewName", Model, new ViewDataDictionary(ViewBag))
    

    then your partial view will not see data from your original ViewBag.

    Remove new ViewDataDictionary(ViewBag), so you should write

    @Html.Partial("PartialViewName", Model)
    

提交回复
热议问题