【发布时间】:2026-02-19 01:30:01
【问题描述】:
无法访问foreach循环中存储过程的SQL select语句的列值
运行代码时出现此错误
enter image description here
这是存储过程
ALTER proc [dbo].[getAuthorBooks]
@id int
as
Begin
select BookName,Paid from Book where AuthorId=@id
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
}
【问题讨论】:
标签: asp.net-mvc stored-procedures