I have my controller working in a way at the moment where the url comes up Home/Collections/Collection?id=1 at the moment, which was my intended functionality. However, I would now like to make the url more friendly. For example, I would like it to become Home/Collections/Summer.
I have the following code in my CollectionsController:
public ActionResult Index()
{
return View(Helper.Helper.ResolvePath("Collections"));
}
//
// GET: /Collections/Collection?id=1
public ActionResult Collection(int id)
{
var collectionModel = ds.GetCollection(id);
return View(Helper.Helper.ResolvePath("Collection"), collectionModel);
}
What do I need to change to get my desired result? Without having a separate ActionResult for each collection (as it will never be a fixed number)?
And here is my Global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
You can define a route like,
Now in your CollectionsController,
Now your url will be like “http://localhost:98765/Collections/Summer”
but i dont undersdtand why you need Home in the url