ASP.NET MVC中如何通过ViewBag实现动态数据传递?
- 内容介绍
- 文章标签
- 相关推荐
本文共计182个文字,预计阅读时间需要1分钟。
我正在尝试将数据库中的值传递给ASP.NET MVC中的视图,过程非常简单。以下是代码片段:
csharppublic 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).FirstOrDefault(); }}
我正在尝试将数据库中的值传递给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' 它应该是这样的:
ViewBag.app_id = app_id;
ViewBag是一种动态类型,这意味着您可以在运行时添加app_id等参数.
本文共计182个文字,预计阅读时间需要1分钟。
我正在尝试将数据库中的值传递给ASP.NET MVC中的视图,过程非常简单。以下是代码片段:
csharppublic 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).FirstOrDefault(); }}
我正在尝试将数据库中的值传递给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' 它应该是这样的:
ViewBag.app_id = app_id;
ViewBag是一种动态类型,这意味着您可以在运行时添加app_id等参数.

