我收到了错误;
严重级代码说明项目文件行错误CS0742查询正文 必须以select子句或group子句结束
导致此错误的原因是什么?我将如何解决?
这是我的控制器
public ActionResult Index()
{
string currentUserId = this.User.Identity.GetUserName();
var list = from o in new TshirtStoreDB().Orders
.Where(o => o.Username == currentUserId)
.OrderBy(o => o.OrderDate)
.Select(o => new MyOrdersViewModel()
{
OrderId = o.OrderId,
Address = o.Address,
FirstName = o.FirstName,
LastName = o.LastName,
City = o.City,
OrderDate = o.OrderDate,
PostalCode = o.PostalCode,
Total = o.Total,
HasBeenShipped = o.HasBeenShipped,
Details = (from d in o.OrderDetails
select new MyOrderDetails
{
Description = d.Product.Description,
Quantity = d.Quantity,
Title = d.Product.Title,
UnitPrice = d.UnitPrice
}).ToList()
}).ToList();
return View(list);
}
没有错误,现在无法查看数据,我的观点是否存在问题?
@model List<T_shirt_Company_v3.ViewModels.MyOrdersViewModel>
@{
ViewBag.Title = "My Orders";
}
<table bgcolor="#00FF00" cellpadding="4" cellspacing="3">
@foreach (var m in Model)
{
<tr>
<td>Order Placed At: @m.OrderDate</td>
<td>Total Cost: @m.Total</td>
<td>Dispatched to: @m.FirstName @m.LastName</td>
<td>Delivery Address: @m.Address <br /> @m.City <br /> @m.PostalCode <br /> </td>
<td>Order Number: @m.OrderId</td>
</tr>
foreach (var d in m.Details)
{
<tr>
<td colspan="3">Product Name: @d.Title</td>
<td>Quantity Ordered: @d.Quantity</td>
<td>Price: @d.UnitPrice</td>
</tr>
}
}
</table>
答案 0 :(得分:0)
问题可能是因为没有向View发送有效模型。请检查一次。
List<T_shirt_Company_v3.ViewModels.MyOrdersViewModel> list = (from o in new TshirtStoreDB().Orders
.Where(o => o.Username == currentUserId)
.OrderBy(o => o.OrderDate)
.Select(o => new MyOrdersViewModel()
{
OrderId = o.OrderId,
Address = o.Address,
FirstName = o.FirstName,
LastName = o.LastName,
City = o.City,
OrderDate = o.OrderDate,
PostalCode = o.PostalCode,
Total = o.Total,
HasBeenShipped = o.HasBeenShipped,
Details = (from d in o.OrderDetails
select new MyOrderDetails
{
Description = d.Product.Description,
Quantity = d.Quantity,
Title = d.Product.Title,
UnitPrice = d.UnitPrice
}).ToList()
}).ToList() select o).ToList();