我正在制作一个简单的网站,我制作了一个菜单,当我点击菜单上的链接时我想重定向其他视图
<!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>
&#13;
这是我的母版页。当我添加@ Url.Action时,Url在当前上下文中不存在。当我点击例如&#34; KitapGoruntule&#34;我想在家里打开视图是KitapGoruntule
答案 0 :(得分:1)
使用request.headers()
会为您创建ActionLink
标记。
在你的情况下:
<a>
创建:
@Html.ActionLink("Kitapları Görüntüle", "KitapGoruntule", "Home")
答案 1 :(得分:1)
它应该可以工作,看起来像缺少对System.Web.Mvc的引用,请在项目中确认该DLL的引用。
编辑: 同时确认MAIN web.config中的以下标记:
<add key="webpages:Version" value="3.0.0.0" />
答案 2 :(得分:0)
您可以使用像这样的链接按钮
<a href="/Home/KitapGoruntule">Kitapları Görüntüle</a>