Reputation: 23
Hay, I'm creating a website like wikipedia and I need to get the id from url to show correct view. This is my route config:
private void ConfigureRoutes(IRouteBuilder routeBuilder)
{
routeBuilder.MapRoute(
"Default",
"{controller=Home}/{action=Index}/{id?}"
);
}
The id will be name of the view that controller will return.
Upvotes: 2
Views: 7944
Reputation: 67175
Where are you getting stuck? The default mapping that Visual Studio sets up for you supports this already. Just add an id
parameter to your controller method and use it to look up your content.
public ActionResult Index(string id)
{
if (id != null)
{
// Lookup topic from id
}
}
Upvotes: 6