Problem with ViewBag and ViewData for Creating Breadcrumbs

2

I need to get back from my controller to my data view project to mount the breadcrumb.

My problem is: If I have ViewBag or ViewData or TempData, and the user is using two different windows, I can show the wrong data.

There is a more "secure" way to pass this data, as well as being present in the model.

    
asked by anonymous 08.10.2015 / 16:50

1 answer

2

The question and answers already exist here , but I think it's worth putting one more example of breadcrumb , considering that I've left the approach simpler in recent times.

Information for mounting a breadcrumb of up to 3 levels already exists in the MVC, within ViewContext . An example can be done as follows:

<ul class="page-breadcrumb">
    <li>
        <i class="fa fa-home"></i>
        <a href="~/">Meu Sistema</a>
        <i class="fa fa-angle-right"></i>
    </li>
    <li>
        <a href="~/@ViewContext.RouteData.Values["controller"]">@(Linguagem.ResourceManager.GetString(ViewContext.RouteData.Values["controller"].ToString()) ?? ViewContext.RouteData.Values["controller"].ToString())</a>
        <i class="fa fa-angle-right"></i>
    </li>
    <li>
        <a href="~/@ViewContext.RouteData.Values["controller"]/@ViewContext.RouteData.Values["action"]/@(ViewContext.RouteData.Values["id"] ?? "")">@(Linguagem.ResourceManager.GetString(ViewContext.RouteData.Values["action"].ToString()) ?? ViewContext.RouteData.Values["action"].ToString())</a>
    </li>
</ul>

Linguagem is a resource ( .resx ) file that contains all strings of proper names of Controllers .

The CSS is based on the Metronic template , whose CSS I put below:

.page-bar .page-breadcrumb {
  display: inline-block;
  float: left;
  padding: 10px 6px;
  margin: 0;
  list-style: none;
}
.page-bar .page-breadcrumb > li {
  display: inline-block;
}
.ie8 .page-bar .page-breadcrumb > li {
  margin-right: 1px;
}
.page-bar .page-breadcrumb > li > a,
.page-bar .page-breadcrumb > li > span {
  color: #888;
  font-size: 13px;
  text-shadow: none;
}
.page-bar .page-breadcrumb > li > i {
  color: #aaa;
  font-size: 14px;
  text-shadow: none;
}
.page-bar .page-breadcrumb > li > i[class^="icon-"],
.page-bar .page-breadcrumb > li > i[class*="icon-"] {
  color: #8c8c8c;
}
    
08.10.2015 / 17:24