Use different action name in breadcrumb

I am using the code below to display a breadcrumb on my site and it works perfectly, but what I’m trying to work out is how to change the action name that’s being used to a name with spaces.

@if (ViewContext.RouteData.Values["controller"].ToString() == "Home")
{
@Html.Label(ViewContext.RouteData.Values["controller"].ToString(), ViewContext.RouteData.Values["controller"].ToString(), ViewContext.RouteData.Values["controller"].ToString())
 }

@if (ViewContext.RouteData.Values["controller"].ToString() != "Home")
{
@:Home > @Html.Label(ViewContext.RouteData.Values["controller"].ToString(), ViewContext.RouteData.Values["controller"].ToString(), ViewContext.RouteData.Values["controller"].ToString())
            if (ViewContext.RouteData.Values["action"].ToString() != "Index")
                {
                    @:> @Html.Label(ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString())
            }
            }

So for example I have a Controller as below:

namespace CristalStandards.Controllers
{
    public class ClaimsController : Controller
    {
        //
        // GET: /Claims/
        public ActionResult Index()
        {
            return View();
        }        

        //
        // GET: /Claims/Diligence/
        public ActionResult Diligence()
        {
            return View();
        }

    }
}

Which then creates a breadcrumb like this:

Home > claims > diligence

But what I would like to have is a breadcrumb like this

Home > claims management > claims and due diligence

So where can I insert ‘claims management’ and ‘claims and due diligence’ into the controller and then use those names in the breadcrumb script at the top of this post, without it affecting anything else.

1 Like

I think I have the correct method in controller as below

namespace CristalStandards.Controllers
{
    public class ClaimsController : Controller
    {
        //
        // GET: /Claims/
        [ActionName("Claims Management")]
        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Claims/Diligence/
        [ActionName("Claims And Due Diligence")]
        public ActionResult Diligence()
        {
            return View();
        }

    }

}

But how do I use that in the breadcrumb, I’m not sure, because when I go to the page its causing a 404 error, so I suppose its taking over and then there no file of that name in Views.

I have read that I need to use BaseModel, but in honesty I cant find a decent enough post from anyone that explains how to use it for what I’m trying to do.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.