0
不能在foreach循环访问存储过程的SQL SELECT语句的列值
此错误occure运行时代码 enter image description here无法访问存储过程值foreach循环在asp.net mvc的
这是存储过程
ALTER proc [dbo].[getAuthorBooks]
@id int
as
Begin
select BookName,Paid from Book where [email protected]
End
这是C#代码 公共的ActionResult埃德它(INT ID){
Author auth = new Author();
parhowDBEntities d=new parhowDBEntities();
var data = d.getAuthorBooks(9).ToList();
int x=data.Count;
ViewBag.AB = data;
Author auth2 = new Author();
auth2 = auth.GetEntity(id);
return View(auth2);
}
这是查看代码
@foreach (var item in ViewBag.AB)
{
@item.BookName
}
我使用连接从多个表中获取数据,所以这不适用于我。 –
所以你可以创建一个你需要的所有财产的模型,我的朋友。然后,可以轻松访问。 – Tomato32