【问题标题】:ViewBag AssignmentViewBag 分配
【发布时间】:2012-06-28 18:20:31
【问题描述】:

我正在尝试将一个值从我的数据库传递到 asp.net mvc 中的视图,非常简单的东西

    public ActionResult SettingsList() {


        using (podio_doc_db db = new podio_doc_db() ) {

            string app_id = db.Configs.Where(r => r.Key == "app.id").Select(r => r.Value).First();
            ViewBag["app_id"] = app_id;

        }

        return View();
    }

但我不断收到此错误

Cannot apply indexing with [] to an expression of type 'System.Dynamic.DynamicObject' 

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-3 viewbag


    【解决方案1】:

    应该是这样的:

    ViewBag.app_id = app_id;
    

    ViewBag 是动态类型,这意味着您可以在运行时添加参数,例如 app_id。

    【讨论】:

      猜你喜欢
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多