0

Currently I have a Controller named StoreController. There are three Categories : books, movies, and games. How can i make sure that the url's

  • http://mywebsite.com/store/books,
  • http://mywebsite.com/store/movies
  • http://mywebsite.com/store/games

match a single action method. Right now, I am having three separate action methods books(); movies(); games(); doing the same thing, i.e listing the products in them

1 Answer 1

3

Did you try like this?

routes.MapRoute(
                "Default", // Route name
                "{controller}/{id}", // URL with parameters
                new { controller = "Store", action = "Index", id = UrlParameter.Optional } // Parameter defaults
                , null }
                )

and you make Controller like

public ActionResult Index(string id)
{
    if(id == "books"){


    }
    else if(id == "movies"){

    }
    else{// this is null case


    }

    return Content("hello");// test
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.