Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

Please help me as i m totally new to asp.net mvc.I want to implement generic breadcrumb in asp.net mvc. So i created a partial view(cshtml) and all it in all pages and in the Partial View,i embed the logic to show BreadCrumbs and its working fine.But problem is that, a page can be open in two ways

1)through dashboard
2)through Menu

My Coding handles only one scenario(either dashboard or menu), Can anyone please simplify this scenario or guide me to apply breadcrumb in all the pages.

So i want this

1)if a user enters Customer's page , from the menu then the breadcrumb should show the hierarchy from the menu like Admin > Customer

2)and if a user enters customer's page from the dashboard then the breadcrumb should show the hierarchy from the dashboard like Dashboard > Customer

Thanks in Advance.

Regards.
Posted
Comments
Krunal Rohit 16-Oct-15 9:11am    
You ViewBag. Set page name in the ViewBag in action method & render its value in appropriate page.

-KR

Lets consider scenario as we are going to use MVC as well as Razor, we can bind the data on the view coming from the Controller.
That controller will fetch such data to bind as Bread-scrum on the view.
As there are two ways of Navigation, you have to concentrate on Actions and Controller.
As this is the only way to find out the current controller as well as current action which will render the current page.
This controller name as well as Action name will be present in the URL.
With the help of this pair, make table in the Database, and add entries for the Bread-scrum.
Make a generic Ajax call to get this data from the Database by passing two in Parameters i.e. Controller Name and Action Name which will results in Bread-scrum name.
Bind this Ajax call's result to the partial view.
This makes generic Bread-scrum.
 
Share this answer
 
Have you seen the open-source solution MvcBreadCrumbs? There's a couple of ways to accomplish it with this Nuget package. You can use attributes on controller methods like this:

C#
[BreadCrumb(Label="Widget")]
public ActionResult ...


or optionally add a static method call to override the label if it's data dependent:

C#
[BreadCrumb(Label="Widget")]
public ActionResult Get(int id)
{
    [make db call]
    BreadCrumb.SetLabel(db.ItemDescription);
    return view(dbModel);
}


Good Luck!
 
Share this answer
 
Comments
Member 14094819 21-Dec-18 8:09am    
But BreadCrumb nuget will fail when we are trying to call from Controller to Controller Right?
Any one Can please send me a solution for solving this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900