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

后端 未结 8 1424
无人共我
无人共我 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:45

    My senario was, I had partial view with Model IEnumerable However I had to pass using, coz Model.SampleModelList can be null

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

    The simple solution was since PartialView is also now part of View every element on View can be accessed by PartialView so I did set the ViewBag data to data-element on View html, instead of ViewBag.

    @Model.Name

提交回复
热议问题