我的导航栏中有一个图像,当我单击该图像时,我希望它路由到索引操作(我的主页)。
[我看到了人们将Url.ActionFor
放在src =""
中的解决方案,但是有了这种解决方案,就没有地方放置我的图像了。
最佳解决方案是什么?
为什么不使用标签修饰图片?
<a href="@Url.Action("actionName", "controller name")"><img src="../../Content/Images/Image.bmp", alt="Alt" /></a>
不知道为什么要将此插入到src
属性中。
您认为:
<a class="my-auto" asp-controller="ControlerName" asp-action="ActionName">
<img src="/path/to/image" alt="logo" class="logo">
</a>
将图像包装在链接到您的操作的标签中:
<a href="@Url.Action("Index", "MyController")"><img src="url_of_navbar_image"></a>