من این کار هم کردم اما باز نشد
ببینید این کنترلر صفحه مورد نظرم
[HttpGet]
public ActionResult Sale()
{
ViewBag.customer = new SelectList(_customerRepository.GetAllCustomers(), "CustomerId", "CustomerName");
ViewBag.Group = new SelectList(_productGroupRepository.GetAllProductGr oup(), "GroupId", "GroupName");
return View();
}
و این هم متد post
[HttpPost]
public ActionResult Sale(Sale sale)
{
if (_productRepository.CheckMojudi(sale.Weight, sale.ProductId))
{
var we = _saleRepository.OrginalWeight(sale.ProductId, sale.Weight);
sale.Username = User.Identity.Name;
sale.DateTime = DateTime.Now;
sale.ProductId = sale.ProductId;
sale.OrginalWeight = we;
sale.TotalPrice = sale.Price * we;
_saleRepository.InsertSale(sale);
_productRepository.Mojudi(sale.Weight, sale.ProductId);
UpdateAll.Refresh();
//ViewBag.customer = new SelectList(_customerRepository.GetAllCustomers(), "CustomerId", "CustomerName", sale.CustomerId);
//ViewBag.Group = new SelectList(_productGroupRepository.GetAllProductGr oup(), "GroupId", "GroupName");
//ViewBag.Product = new SelectList(_productRepository.GetAllProducts(), "ProductId", "ProductName");
return RedirectToAction("Sale","Sale");
}
else
{
ModelState.AddModelError("Weight", @"موجودی محصول کم است");
var grId = _productRepository.GetGrouProduct(sale.ProductId);
ViewBag.customer = new SelectList(_customerRepository.GetAllCustomers(), "CustomerId", "CustomerName", sale.CustomerId);
ViewBag.Group = new SelectList(_productGroupRepository.GetAllProductGr oup(), "GroupId", "GroupName", grId);
return View();
}
}
مشکل اصلی من اینه که الان اگه قسمت if کامل اجرا بشه برمیگرده ولی بخش else اجرا بشه ارور برمیگردونه که میخوام بره همون صفحه ولی هر 2 تا ddl از نو پر میشن و روی index = 0 قرار میگیرن
چی کار کنم ؟
ممنون میشم راهنمایی بفرمایید
دوستان یکی کمک کنه خیلی واجبه