Url.Action 在布局页面上不起作用



我正在制作简单的网站,我制作了一个菜单,当我单击菜单上的链接时,我想重定向其他视图

<!DOCTYPE html>
<html>
<head>
<title>@Page.Title</title>
@RenderSection("head", required: false)
<style>
body {
margin: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 25%;
background-color: #555;
position: fixed;
height: 100%;
overflow: auto;
}
li a {
display: block;
color: white;
padding: 8px 16px;
text-decoration: none;
}
li a.active {
background-color: #4CAF50;
color: #000;
}
li a:hover:not(.active) {
background-color: #f1f1f1;
color: #000
}
</style>
</head>
<body>
<div>
<ul>
<li><a href="@Url.Action("KitapGoruntule","Home")">Kitapları Görüntüle</a></li>
<li><a href="#news">Kitap Kiralama</a></li>
<li><a href="#contact">Öğrencileri Görüntüle</a></li>
<li><a href="#about">Öğrenci Ekle</a></li>
<li><a href="#about">Kitap Ekle</a></li>
<li><a href="#about">Kiralanmış Kitap Listesi</a></li>
<li><a href="#about">Görevli Atama</a></li>
<li><img src="~/img/tpl_logo.gif" style="height:130px;width:325px;margin-left:5px" /></li>
</ul>
</div>
<div style="margin-left:25%;padding:1px 16px;height:1000px;">
@RenderBody()
</div>
</body>
</html>

这是我的母版页。 当我添加@Url时,操作 URL 在当前上下文中不存在。 当我单击例如"KitapGoruntule"时,我想在主页名称中打开视图是KitapGoruntule

使用ActionLink将为您创建<a>标签。 在您的情况下:

@Html.ActionLink("Kitapları Görüntüle", "KitapGoruntule", "Home")

创建:

<a href="/Home/KitapGoruntule">Kitapları Görüntüle</a>

它应该可以工作,看起来缺少对System.Web.Mvc的引用,请确认项目中该DLL的引用。

编辑: 还要在主 web.config 中确认以下标记:

<add key="webpages:Version" value="3.0.0.0" />

你可以像这样使用链接按钮

<a href="/Home/KitapGoruntule">Kitapları Görüntüle</a>

最新更新