public ActionResult Index(Product product) { if (product.Name != "P1") { ModelState.AddModelError("Name", "الاسم"); } if (!ModelState.IsValid) { return View(product); } return RedirectToAction("Index"); }
public ActionResult Index() { //var categories = new List<SelectListItem> { // new SelectListItem { Text = "A 1", Value = "P1",Disabled=true,Group=new SelectListGroup { Name="B"}}, // new SelectListItem { Text = "A 2", Value = "P10",Selected=true,Group=new SelectListGroup { Name="A"} }, // new SelectListItem { Text = "A 3", Value = "P12",Group=new SelectListGroup { Name="A"} }, // new SelectListItem { Text = "A 4", Value = "P" ,Group=new SelectListGroup { Name="B"}} //}; //ViewBag.Categories = categories; Product product = new Product(); product.Type = Models.Type.Special; return View(product); }