I'm new of asp.net mvc. I'm making a small application of shopping car. I use a shoppingCar view and use partialview to show products in shoppingcar view. And I want to check the BuyerName and Deliver data from ShoppingCarView and the products buyer select in ProductView.
How can I get the data from shoppingcarview and productsview. Is this practical or possible to do?How should I do.
ShoppingCarVM
public class ShoppingCarViewModel
{
[Required(AllowEmptyStrings = false, ErrorMessage = "Buyer name could not be null")]
[DisplayName("購買者姓名")]
public string BuyerName { get; set; }
//[System.Web.Mvc.Remote("DateValid", "StringValid", ErrorMessage = "日期必須在訂購日三天以後")]
[DisplayName("送貨時間")]
public DateTime DeliverDate { get; set; }
public List<ProductViewModel> pList;
}
ProductVM
public class ProductViewModel
{
[DisplayName("商品")]
public string ProductName { get; set; }
[DisplayName("價錢")]
public int ProductPrice { get; set; }
[DisplayName("數量")]
public int ProductAmt { get; set; }
[DisplayName("商品區")]
public string ProductGroup { get; set; }
[DisplayName("是否購買")]
public bool ProductBuy { get; set; }
}
I use this line at main view giving pList to partialView
@Html.Partial("ShoppingCarProducts", Model.pList)
But when I want to post the data back at the controller
[HttpPost]
public ActionResult ShoppingCar(ShoppingCarViewModel data)
{
if (ModelState.IsValid)
{
return View();
}
return View(data);
}
the data.pList is always null.
Does anyone know how to fix it or another way to do this.
Thanks for read this.