1

What might be the reason my breadcrumbs aren't shown on the page when the address is like http://localhost:53732/Details/Index/1 enter image description here

But it works if I manually rewrite the address like this http://localhost:53732/Details/Index?id=1 enter image description here

Here is my Mvc.sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
  <mvcSiteMapNode title="Home" controller="Home" action="Index">
    <mvcSiteMapNode title="Listing" controller="Listing" action="Listing" key="Details">
    </mvcSiteMapNode>
  </mvcSiteMapNode>
</mvcSiteMap>

And here is the method which returns my View Details/Index:

namespace OurNewShop.Controllers
{
    public class DetailsController : Controller
    {
        [MvcSiteMapNode(Title = "DetailsPage", ParentKey = "Details")]
        public ActionResult Index(int id)
        {
            using (ProductContext context = new ProductContext())
            {
                Product pr = context.Products.Include(y => y.ProductImages).FirstOrDefault(y => y.ProductId == id);
                ViewBag.ImagePath = Constants.Constants.ImagePath;
                return View(pr);
             });
            }
        }
    }
}

What is the solution to see it?

0

1 Answer 1

1

Optional parameters must be mentioned in mvcSiteMapNode within web.sitemap in order to make the breadcrumbs and navigation work properly. Try including "id", and "preservedRouteParameters" as shown below.

<mvcSiteMapNode title="Home" controller="Home" action="Index" id="*" preservedRouteParameters="id"/>
Sign up to request clarification or add additional context in comments.

4 Comments

then should I write [MvcSiteMapNode(Title = "DetailsPage", ParentKey = "Details")] before public ActionResult Index(int id)?
and do I have to specify id?
thank you, adding preservedRouteParameters="id" and deleting [MvcSiteMapNode(Title = "DetailsPage", ParentKey = "Details")] helped me!
Glad it worked... yes, id is just a name of the parameter, if you have multiple parameters in your route, then you would need to specify them as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.