我的_Layout.cshtml
包含
Html.Action("GetCartList", "Shared");
ShoppingCartViewModel scvm = (ShoppingCartViewModel)ViewData["ShoppingCartViewModel"];
我的控制器
[ChildActionOnly]
public ShoppingCartViewModel GetCartList()
{
var results = new ShoppingCartViewModel
{
Message = "",
SomeOtherProperty = "Other"
};
ViewData["ShoppingCartViewModel"] = results;
return results;
}
问题是为什么scvm
总是为空?
当控制器“被击中”时,值会成功加载到ViewData["ShoppingCartViewModel"]
我希望我能做点像......
ShoppingCartViewModel scvm = Html.Action("GetCartList", "Shared");
答案 0 :(得分:2)
在您的子操作中,将ViewData设置为Glide.with(context).load(R.drawable.macarrones).into(imageView);
。
ParentActionViewContext
在你的布局中,
[ChildActionOnly]
public void GetCartList()
{
var results = new ShoppingCartViewModel
{
Message = "",
SomeOtherProperty = "Other"
};
ControllerContext.ParentActionViewContext.ViewData["ShoppingCartViewModel"]=results;
}