I wrote a partial method like this :
public ActionResult _StatePartial()
{
ViewBag.MyData = new string[] { "110", "24500" };
return View();
}
在_Layout
页面中渲染_StatePartial
视图:
@Html.Partial("_StatePartial")
这是我的部分视图代码:
@{
string[] Data = (string[])ViewBag.MyData;
}
<div id="UserState">
Reputation: @Html.ActionLink(Data[0], "Reputation", "Profile") |
Cash: @Html.ActionLink(Data[1], "Index", "FinancialAccount")
</div>
但是当我运行这个项目时,_
StatePartial
方法没有被调用,ViewBag
始终为null。Server Error in '/' Application.
Object reference not set to an instance of an object.
请注意,这些参数不是我的模型字段,而是通过调用Web服务方法计算得出的。但我会在我的问题中不断设置这些值。
我该怎么办? 有没有关于将参数传递给局部视图的想法? 谢谢。