How to make the Badge that is in the navbar that is in the _Layout.cshtml capture in all the navigation of my application information of my ControllerWarnings?
In my Con
You can have your action method returns the HTML for your badge, which includes the data(warning number) as well.
public class WarningController : Controller
{
public ActionResult Badge()
{
int contWarning = 10; // temp hard coded value for demo;
// Replace the hard coded value
// with your existing code to get the data from database
return PartialView("Badge",contWarning);
}
}
Now in your Badge.cshtml
, which is storngly typed to int
type, render the HTML you want.
@model int
<span class="badge">
@Model
</span>
Now in your layout(_Layout.cshtml
), call this render the output of this Badge action method using the Html.Action
method.
@Html.Action("Badge","Warning")
Make sure you are returning a partial view (which does not have it's own layout) using PartialView
instead of View
method. If your Badge action method is returning a view which has the same layout file, that will cause an infinite loop and you will get the StackOverflow exception.