假设我有一个 Controller ,其方法返回一个 PartialView。如果我想将数据添加到 ViewBag,是否必须全部放在一个方法中?
例如:
public PartialViewResult GetPage()
{
ViewBag.Example = "Here is some text.";
AddMoreToViewBag();
return PartialView();
}
private void AddMoreToViewBag()
{
ViewBag.Example2 = "More text";
}
在上面的示例中,Example1 和 Example2 是否都可用于返回的 PartialView?
最佳答案
In the above example, will both Example1 and Example2 be available to the PartialView that is returned?
是的,它是可用的。
关于c# - ASP.NET MVC4 - 以不止一种方法添加到 ViewBag?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21403399/