public ActionResult Create(SubcategoryModelView model) { try { // TODO: Add insert logic here var newSubCategory = new SubcategoryModelView { subCategory = new SubCategory() { Subcat_name = model.subCategory.Subcat_name , CategoryId = model.subCategory.CategoryId } }; _db.AddEntity(newSubCategory.subCategory); return(RedirectToAction(nameof(Index), model.subCategory.CategoryId)); } catch { return(View()); } }
public ActionResult Index(int id) { ViewBag.categoryname = Category.GetByID(id).cat_name; ViewBag.cateID = Category.GetByID(id).TD; var SubcategoryModel = new SubcategoryModelView() { subCategories = _db.Get().Where(x => x.CategoryId == id).ToList() }; return(View(SubcategoryModel)); }