First I want to show code

routes.MapRoute(
            name: "SubCategory",
            url: "Category/{categoryName}/{subName}",
            defaults: new { controller = "Categories", action = "SubCategory", categoryName = "", subName = "" }
        );

this is my route categoryName and subName are variables

// GET: Category/{categoryName}/{subName}
    public ActionResult SubCategory(string categoryName, string subName)
    {
        CategoriesViewResult viewResult = new CategoriesViewResult();
        viewResult.Categories = _db.Categories.ToList();
        viewResult.CurrentSubCategory = _db.SubCategories.First(x => x.Category.CategoryName == categoryName && x.SubCategoryName == subName);

        return View(viewResult);
    }

this is my method; but I get 404. how should i write my routes.

UPDATE

this is above default route.

Related posts

Recent Viewed