@Url.Action(“Login”, “HECAccount”) 在 cshtml(layout)中不起作用

@Url.Action("Login", "HECAccount") not working in cshtml (layout)

本文关键字:cshtml layout 不起作用 Action Login @Url HECAccount      更新时间:2023-09-26

我正在为我的 asp.net mvc 4 Web应用程序创建垂直菜单。

所以我提到了这个链接来整合到我的事情中.

所以我编辑了我的 _HECLayout.cshtml(包含在"~/视图/共享/")文件中,就像这样

   <!DOCTYPE html>
<html lang="en">
    <head>

<script type="text/javascript" src='~/Scripts/jquery-2.0.0.min.js'/></script>   
 <link href="~/Content/font-awesome.min.css" rel="stylesheet" />
 <link href="~/Content/font-awesome.css" rel="stylesheet" />
 <link href="~/Content/css.css" rel="stylesheet" /> 

    <script>
        $(document).ready(function () {
            $('ul.formxd li a').click(
                function (e) {
                    e.preventDefault(); // prevent the default action
                    e.stopPropagation; // stop the click from bubbling
                    e.stopPropagation; // stop the click from bubbling
                    $(this).closest('ul').find('.selected').removeClass('selected');
                    $(this).parent().addClass('selected');
                });
        });
    </script>   

        <meta charset="utf-8" />
        <title>@ViewBag.Title - Higher Education Council</title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
        @Styles.Render("~/Content/css")
        @Scripts.Render("~/bundles/modernizr")
        <div id="header">
             <div id="top-area">
                <div id="logo-area">
                   <img src="~/Images/hec-logo.png" />
                </div>

    </head>
    <body>
        <header>
            <div class="content-wrapper">
                   <div class="float-right">
                     <section id="text-view" style="display: inline; width: 100%; text-align: right;" >
                       <p><i>Higher Education Institutes </i></p>
                    </section>
                    </div>
                 </div>
        </header> 
          @RenderSection("featured", required: false)
        <div id="menu_area">
            <div class="hec_admin_menu" >
               <ul class="formxd">

        <li class="welcome"><a class="welcome"><i class="icon-fa-university"></i>Welcome HEC</a></li>
        <li ><a class="dashboard" href="#"><i class="icon-dashboard"></i>Dashboard</a></li>
        <li ><a class="reports" href="#"><i class="icon-file"></i>Reports</a></li>
        <li><a class="administrator" href="#"><i class="icon-user"></i>Administrator</a></li>
        <li><a class="search" href="#"><i class="icon-search"></i>Search</a></li>
        <li><a class="logout" href="@Url.Action("Login", "HECAccount")"><i class="icon-signout"></i>Logout</a></li>
    </ul>
            </div>

            <div class="hec_admin_body">
            <section class="content-wrapper main-content clear-fix">
                @RenderBody()
            </section>
           </div>
        </div> 
        <footer>
        </footer>
        @Scripts.Render("~/bundles/jquery")
        @RenderSection("scripts", required: false)
    </body>
</html>

它提供了流畅的视图,就像我在这里提到的演示一样,但注销网址操作无法正常工作。并且所有网址都无法正常工作,

任何建议要克服他的麻烦

<li><a class="logout" href="@Url.Action("Login", "HECAccount")"><i class="icon-signout"></i>Logout</a></li>
当我

尝试像上面这样插入jquery引用时,我遇到了同样的错误,链接不起作用

所以我提到了这个链接

这是一种给 jquery 引用 HTML 页面的方法,但在 CSHTML 中,当你插入@Scripts.Render("~/bundles/jquery")时,你不需要像这里那样逐个添加引用,

所以删除<script type="text/javascript" src='~/Scripts/jquery-2.0.0.min.js'/></script>

@Scripts.Render("~/bundles/jquery")保持在代码下

如果您的项目没有"jquery-2.0.0.min.js"文件,请手动插入到"~/脚本"文件夹中