0

Firstly, I don't expect to be handed an answer on my plate, however any examples you think will help me will be readily received! I am mainly struggling with how to phrase my question due to being unfamiliar with the terminology and therefore, have not found many suitable resources as of yet.

I have a .net core 2 mvc application. On one page "home/categories" I have a list of items from a database. I wish to click on one of these items for example, tents, and pass a subset of data to a generic layout view that will take data from my model I have just passed in and display a list of products.

I would like the url to be home/categories/tents. I would be using this generic view for many other categories.

I have come across articles about URL Routing. Is this what I need to be looking at to get my solution?

If not URL Routing, should I be looking at a solution involving passing parameters? For example, I see urls containing, eg, categories/?=tents?=summertents. ( I do not know what this method is called, or whether it is suitable. )

Thank you for any help.

B.Hawkins
  • 353
  • 5
  • 13
  • You just need a `public ActionResult categories(string category)` method, and a route definition for it - `url : "Home/Categories/{category}"` –  Jan 22 '18 at 21:54
  • See [MVC Routing template to represent infinite self-referential hierarchical category structure](https://stackoverflow.com/a/48132102/181087) – NightOwl888 Jan 23 '18 at 06:34

1 Answers1

0

You could definitely combine both methodologies. I would say using the URL Routing to get you to home/categories/tents and from there if you want to further filter results use parameters (home/categories/tents?=summertents).

I think this gives a clean look and ability to manage filtering parameters easier.

    public class ProductsController : Controller
    {
       //GET /Products/Categories
       public void Categories()
      {
        //return your list 
      }
      //GET /Products/Tents?season=summertime
      public void Tents(string? season)
     {
       //return a list of tents in a particular season
     }
   }
wiz
  • 1
  • 1
  • 2