我已经为现有的SQL DB创建了一个数据库实体。
但查询不会返回我期待的数据
namespace WebApplication5.Controllers
{
public class EmployeeController : Controller
{
// GET: Employee
public ActionResult Index()
{
List<string> orderIDs = new List<string>();
using (var db = new WebApplication5.Models.BTP_NYAEntities())
{
var query = from b in db.FilledOrders
select b;
//Console.WriteLine("All blogs in the database:");
foreach (var item in query)
{
//Console.WriteLine(item.OrderID);
orderIDs.Add(item.OrderID.ToString());
}
}
ViewData["MyData"] = orderIDs;
return View(orderIDs);
}
}
}
查看:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Employee Index Page</title>
</head>
<body>
<div>
<h1>Employee Index Page</h1>
@{
var categories = (List<string>)ViewData["MyData"];
foreach(var item in categories)
{
<p>This is a test emp index page @item</p>
}
}
</div>
</body>
</html>