vote up 2 vote down
star
1

Do I need a separate controller for the below?

http://localhost/bookmarks --> bookmarks controller http://localhost/bookmark/{bookmarkid} --> bookmark controller

Is there any way I can combine them both into one controller? I want to keep the uri's the same i.e. bookmark singular indicating fetch a single bookmark.

Thanks

offensive?
add comment

1 Answer:

vote up 3 vote down
check

Assuming a C# development environment

Global.asax:

routes.MapRoute(
  "Bookmarks",
  "bookmarks",
  new { controller = "Bookmarks", action = "Bookmarks"}
);

routes.MapRoute(
  "Bookmark",
  "bookmark/{bookmarkid}",
  new { controller = "Bookmarks", action = "Bookmark" }
);

BookmarksController:

public ActionResult Bookmarks()
{
   //Get all bookmarks, I presume. :)
   return View();
}

public ActionResult Bookmark(string bookmarkid)
{
   //Do stuff with the bookmark id
   return View();
}

Using this routing scheme, http://localhost/bookmarks will hit the Bookmarks action in the Bookmarks controller, and http://localhost/bookmark/123456 will hit the Bookmark action in the Bookmarks controller.

link|offensive?
comments (2)

Your Answer:

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.