我正在尝试将一个值从我的数据库传递到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' 发布于 2012-06-29 02:21:42
应该是这样的:
ViewBag.app_id = app_id;ViewBag是一种动态类型,这意味着您可以在运行时添加参数,如app_id。
https://stackoverflow.com/questions/11250661
复制相似问题