i want to create breadcrumb with MvcSiteMap in mvc5. i wrote below code. but i want to when i click on first , second , ... their Id pass to View. but it dose not work. i do it right?
//Controller Name=News
Home
News
first //id=1
second //id=2
third // id=3
About
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="News" controller="News" action="Index" key="News">
</mvcSiteMapNode>
<mvcSiteMapNode title="About" controller="About" action="Index"/>
[MvcSiteMapNode(Title = "News", ParentKey = "News")]
public ActionResult News(int id)
{
ViewBag.id = id;
return View();
}
As stated in the documentation, you must configure all custom route parameters (including id) explicitly. You can create a 1 to 1 relationship with the action method by including the key in PreservedRouteParameters or you can create a 1 to many relationship with the action by creating a separate node for every route value combination.
1 to 1 Relationship
Using XML:
Or Using .NET Attributes:
1 to Many Relationship
Using XML:
Or Using .NET Attributes:
Or Using a Dynamic Node Provider:
With Definition Node in XML:
Or With Definition Node in .NET Attributes:
Dynamic Node Provider Implementation (required for either of the 2 definition nodes above):