繁体   English   中英

网址操作在布局页面上不起作用

[英]Url.Action not working on layout page

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

 <!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的视图

使用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的引用。

编辑:还要在您的MAIN web.config中确认以下标签:

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM