kenticokentico-mvc

Kentico MVC - How to get Home Page URL in _Layout.cshtml


I am trying to get a home page url in layout navigation so I can get back to home page to be precise, so that users can get to home page very easily.

I now I can just write /home but I want it to be like dynamically inputed if you know what I mean.

Is there any function in Kentico MVC that can give me that path URL or not. Here is my code.

_Layout.cs:

@using Kentico.PageBuilder.Web.Mvc

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    @* Dynamically resolves the page's title *@
    <title>Medio Clinic - @ViewBag.Title</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
    <link href="http://fonts.googleapis.com/css?family=Lato:400,700italic&amp;subset=latin,latin-ext" rel="stylesheet" type="text/css">
    <link href="http://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">

    @* Loads the styles.css resource *@
    @Styles.Render("~/Content/css")
    @* Razor section for additional page-specific styles *@
    @RenderSection("styles", required: false)
</head>

<body>
    <header>
        <nav class="navbar navbar-light bg-light">
            <div class="container-fluid">
                <div class="d-flex">
                    <a href="" title="SamedWear" class="logo">SamedWear</a>
                </div>
                <nav>
                    @Html.Action("GetMenu", "Menu")
                </nav>
            </div>
        </nav>

        <div class="col-sm-offset-3 col-sm-6">
            <div class="col-sm-6">
                
            </div>
            <div class="col-sm-6 nav">
               
            </div>
        </div>
        <div class="clearfix"></div>
    </header>

<div class="container">
    @RenderBody()
</div>
   

    <footer>
        <div class="col-sm-offset-3 col-sm-6">
            <div class="row">
                <div class="col-sm-6">
                    <h4>MEDIO clinic</h4>
                    <ul>
                        <li><i class="fa fa-map-marker"></i> Address: <address>Ul.Patriotske Lige br. 94, Kakanj</address></li>
                        <li><i class="fa fa-envelope-o"></i> E-mail: <a href="mailto:info@medio-clinic.com" title="Email us">samed.skulj@grm.digital</a></li>
                        <li><i class="fa fa-phone"></i> Broj telefona: <a href="tel:061957488" title="Pozivite nas">061-957-488</a>
                    </ul>
                </div>
                <div class="col-sm-6">
                    <span class="cms">Powered by <a href="http://www.kentico.com" title="Kentico Xperience">Kentico Xperience for ASP.NET</a></span>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </footer>
    @RenderSection("scripts", required: false)
</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</html>

This is the tag where I want to href the home page

<a href="" title="SamedWear" class="logo">SamedWear</a>

Here is my pages interface: enter image description here

And content-base routing is like this: enter image description here


Solution

  • You can use Xperience's UrlHelperExtensions, and call PageUrl and pass the NodeAliasPath in. For your scenario you would do:

    <a href="@Url.Kentico().PageUrl("/Home")" title="SamedWear" class="logo">SamedWear</a>