Well I'm new in Asp.net MVC and facing problem. I have two dropdown lists "Company" and "Product" When I select company and one of it's product it appears in below table using jquery. Now I want to show it's quantity and price of selected product as well from database. I'm doing this.
Here is my Controller Code
- [Authorize]
- [AllowAnonymous]
- public ActionResult Details()
- {
- ViewBag.Companies = db.Companies.ToList();
- return View();
- }
- private IList GetProduct(int CompanyId)
- {
- var data = db.Products.Where(m => m.CompanyId == CompanyId).ToList();
- return data;
- }
- [AcceptVerbs(HttpVerbs.Get)]
- public JsonResult LoadProductsByCompanyId(string CompanyId, string cn)
- {
- Cname = cn;
- var ProductList = this.GetProduct(Convert.ToInt32(CompanyId));
- var ProductsData = ProductList.Select(m => new SelectListItem()
- {
- Text = m.ProductName,
- Value = m.ProductId.ToString(),
- });
- return Json(ProductsData, JsonRequestBehavior.AllowGet);
- }
- [AcceptVerbs(HttpVerbs.Post)]
- public JsonResult GetProductById(string ProductId)
- {
- sampledb4Entities db = new sampledb4Entities();
- int pid = Convert.ToInt32(ProductId);
- var Product = db.Products.Where(x => x.ProductId == pid).SingleOrDefault();
- return Json(Product, JsonRequestBehavior.AllowGet);
- }
And Here Is my View Code
- class="producttable">
- @Html.DisplayNameFor(model => model.CompanyName)
- @Html.DisplayNameFor(model => model.ProductName)
- Product Quantity
- Product Price
Sachin SinghPosted Oct 19, 2020, 8:13 AM
Mageshwaran RPosted Oct 19, 2020, 11:02 AM