Kentico MVC - 如何在 _Layout.cshtml 中获取主页 URL

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

我正在尝试在布局导航中获得主页url,以便我可以准确地返回主页,以便用户可以非常轻松地访问主页。

我现在可以写 /home 但我希望它像动态输入一样,如果你明白我的意思的话。

Kentico MVC 中是否有任何函数可以为我提供该路径 URL 或不。这是我的代码。

_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>

这是我要 href 主页的标签

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

这是我的页面界面:

基于内容的路由是这样的:

您可以使用 Xperience 的 UrlHelperExtensions,然后调用 PageUrl 并传入 NodeAliasPath。对于您的场景,您可以这样做:

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