asp.net mvc中ViewData赋值一个dynamic类型,cshtml如何获取值?例子如下:
例子:Controller1:publicActionResultIndex(){ViewData["a1"]=new{a=1,b="ccc"};returnView()...
例子:
Controller1:
public ActionResult Index(){
ViewData["a1"] = new { a=1,b="ccc"};
return View();
}
Index.cshtml:
@{
dynamic a1 = ViewData["a1"]; //这里断点调试都还正常
int a = a1.a; //这里会获取不到a的值,并报错
string b = a1.b; //这里会获取不到a的值,并报错
} 展开
Controller1:
public ActionResult Index(){
ViewData["a1"] = new { a=1,b="ccc"};
return View();
}
Index.cshtml:
@{
dynamic a1 = ViewData["a1"]; //这里断点调试都还正常
int a = a1.a; //这里会获取不到a的值,并报错
string b = a1.b; //这里会获取不到a的值,并报错
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询