在这里,我的项目有一个下拉列表。但在这里我坚持获取选定的值。我的尝试如下。但仍然无法从下拉列表中获取选定的项目
@Html.DropDownListFor(m => m.ProductType, (SelectList)ViewBag.ListOfCategories, new { @class = "form-control"})
型号代码
[Required]
public string ProductType { get; set; }
控制器
[HttpPost]
public ActionResult AddProduct(ICS.Models.ProductsModels.Products model)
{
ProductController _ctrl = new ProductController();
_ctrl.AddorUpdateProduct(new ICS.Data.Product
{
ProductName = model.ProductName,
ProductType = model.ProductType,
IsFixed = model.PriceSettings,
ItemPrice = model.ItemPrice,
PurchasePrice = model.PurchasePrice,
Vat = model.Vat,
WholeSalePrice = model.WholeSalePrice,
Comments = model.Comments
});
return View(model);
}
[HttpGet]
public ActionResult AddProduct()
{
ViewBag.ListOfCategories = new SelectList(_cat.GetCategory(), "CategoryId", "CategoryName");
return View();
}