【发布时间】:2017-08-02 18:08:38
【问题描述】:
我正在制作简单的网站,我制作了一个菜单,当我点击菜单上的链接时,我想重定向其他视图
<!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.Action Url 在当前上下文中不存在。当我点击例如“KitapGoruntule”时,我想在主页名称中打开视图是 KitapGoruntule
【问题讨论】:
-
你的Route.Config中是否有匹配的路由,Controller中是否有匹配的Action?
-
查看@AlanBuchanan 所说的内容并考虑使用
@Html.ActionLink。 -
@AlanBuchanan 我如何理解匹配我是 mvc 上的新手你能向我解释更多
-
您是否收到错误消息?
-
是的,当我使用 url.action Url.Action Url 在当前上下文中不存在。当我使用 html.Action CS1061 时:“HtmlHelper”不包含“ActionLink”的定义,并且找不到接受“HtmlHelper”类型的第一个参数的扩展方法“ActionLink”(您是否缺少 using 指令或程序集引用?)。我需要使用 标签因为 css 文件
标签: c# asp.net-mvc razor