【发布时间】:2014-11-23 12:56:13
【问题描述】:
我的控制器中有以下内容:
public ActionResult Index(int? id)
{
int projectId = (int)id;
//Get the project name to use in the view
var projName = from p in db.Projects where p.ID == id select p.ProjectName;
ViewBag.projectName = projName.ToString();
//Rest of code ommitted
在我看来:
<p>There are no actors for the @ViewBag.projectName yet.</p>
问题是,我的视图正在呈现以下内容,而不是我的项目名称:
SELECT [Extent1].[ProjectName] AS [ProjectName] FROM [dbo].[Project] AS [Extent1] WHERE [Extent1].[ID] = @p__linq__0 还没有演员。
我已尝试根据此问题 Passing query results in a viewbag 将代码更改为 ViewBag.projectName = projecName.ToList();,但结果如下:
There are no actors for the System.Collections.Generic.List1[System.String] 还没有。
我在这里做错了什么?
帮助非常感谢。
【问题讨论】:
标签: asp.net-mvc entity-framework