I'd like to track an id in the route开发者_JS百科 if it's possible? This is pretty much what I want:
/groups/{id} - Show group
/groups/{id}/forum/topic/{id} - Show forum topics for the group
/groups/{id]/calendar/ - Show the calendar for the group
As you see I want to keep track of what group the user is in by the url, instead of let's say a cookie.
Thanks!
Have you defined {id}
in your routes, e.g.:
routes.MapRoute(
"",
"groups/{id}/forum/topic/{topicId}",
new { controller = "Forum", action = "Topic" });
And into your controller:
public class ForumController : Controller
{
public ActionResult Topic(int id, int topicId)
{
}
}
It's not really clear how you want to track it....
This would work as long as all the possible Urls are generated with the Id. For these routes, you can access the {id} using the following:
int id = int.Parse(RouteData.Values["id"].ToString());
It may be cumbersome to ensure every link on each page contained the Id. No static Urls would be allowed. For example, if the user clicked to the homepage or to /about, the Id would be lost.
精彩评论