我面临的下一个问题:“System.Dynamic.DynamicObject”不包含定义“属性名”
我试图运行.NET MVC站点使用ViewBag一些数据传递给我的视图。 这里是我设置VeiwBag的方法。
[HttpGet]
[AllowAnonymous]
public ActionResult Start()
{
ViewBag.BanReason = null;
int userId;
//Request with UserId, display ban reason if necessary
if (Request.Params["UserId"] != null && int.TryParse(Request.Params["UserId"], out userId))
{
ViewBag.BanReason = CheckIfUserBanned(userId);
}
ViewBag.Users = MvcApplication.Users;
return View();
}
当我将值分配给所述ViewBag(例如ViewBag.BanReason = NULL;)我有与该消息
'System.Dynamic.DynamicObject' 的RuntimeBinderException不包含定义为 'BanReason'。
我使用Visual Studio 2012与.NET 4.5和本地IIS服务器与.NET 4.0的ApplicationPool。在另一台具有相同配置的计算机上,所有工作都很好,并且不会引发异常情况。
请不要建议使用其他技术,如ViewData [“”]和创建一个单独的模型,我不想改变在另一台机器上很好地工作的代码。
我认为这是miss-configuration问题。任何猜测将不胜感激。 感谢
你在哪里使用'ViewBag.BanReason' – Satpal
它使用在Start.cshtml @if(ViewBag.BanReason我们展示的代码!= null) { } – Groove
你可以发布堆栈跟踪吗? – Slavo