model代碼如下:
public class Orders
{
[Key]
public int OrdersId { set; get; }
//訂單號
public string OrdersNum { set; get; }
public string ProductName { set; get; }
public int ProductId { set; get; }
public string PriceName { set; get; }
public int PriceId { set; get; }
//訂購時間
public DateTime PlaceOrdersTime { set; get; }
//付款時間
public DateTime PaymentTime { set; get; }
//零售價
public decimal ProposalPrice { set; get; }
//結算價
public decimal SettlementPrice { set; get; }
//成本價
public decimal CostPrice { set; get; }
//訂購數量
public int OrderQuantity { set; get; }
//總價
public decimal TotalPrice { set; get; }
//支付方式
public string PayMode { set; get; }
//支付總金額
public decimal PayTotalPrice { set; get; }
//訂單狀態
public string OrdersState { set; get; }
//哪個用戶下的訂單
public string UserId { set; get; }
public virtual ICollection<OrdersInfo> OrdersInfo { get; set; }
}
public class OrdersInfo
{
[Key]
public int OrdersInfoId { set; get; }
public int OrdersId { set; get; }
//聯系人
public string Contacts { set; get; }
public string PhoneNumber { set; get; }
public string IdCardNumber { set; get; }
//使用日期
public DateTime UseDate { set; get; }
//驗證碼
public string Code { set; get; }
//驗證碼數量
public int CodeQuantity { set; get; }
//驗證碼未使用數量
public int CodeNotUsedQuantity { set; get; }
//驗證碼使用數量
public int CodeUseQuantity { set; get; }
//驗證碼有效期
public DateTime CodeShelfLife { set; get; }
//驗證碼核銷時間
public DateTime CodeUsedTime { set; get; }
public string Remark { set; get; }
public virtual Orders Orders { get; set; }
}
控制器代碼如下:
public ActionResult RestaurantOrdersList(string OrdersNum, string ProductName, string Contacts, string PhoneNumber, int page = 1)
{
ViewBag.OrdersNum = OrdersNum;
ViewBag.ProductName = ProductName;
ViewBag.Contacts = Contacts;
ViewBag.PhoneNumber = PhoneNumber;
int pageSize = 10;
var OrdersDb = from a in db.Orders
join b in db.OrdersInfo
on new { a.OrdersId } equals new { b.OrdersId }
select new { a, b };
var userId = User.Identity.GetUserId();
OrdersDb.Where(s => s.a.UserId == userId);
if (!string.IsNullOrEmpty(OrdersNum))
{
OrdersDb = OrdersDb.Where(s => s.a.OrdersNum.IndexOf(OrdersNum) > -1);
}
if (!string.IsNullOrEmpty(ProductName))
{
OrdersDb = OrdersDb.Where(s => s.a.ProductName.Contains(ProductName));
}
if (!string.IsNullOrEmpty(Contacts))
{
OrdersDb = OrdersDb.Where(s => s.b.Contacts.Contains(Contacts));
}
if (!string.IsNullOrEmpty(PhoneNumber))
{
OrdersDb = OrdersDb.Where(s => s.b.PhoneNumber == PhoneNumber);
}
ViewBag.RestaurantOrdersList = OrdersDb.OrderByDescending(x => x.a.PlaceOrdersTime).ToPagedList(page, pageSize);
return View();
}
View代碼如下:
@foreach (var l in list)
{
@l.a.ProductName
}
錯誤如下:
caozhy 兄弟,還是不行。