如何在单击时将img src路由到控制器操作

问题描述 投票:0回答:3

我的导航栏中有一个图像,当我单击该图像时,我希望它路由到索引操作(我的主页)。

[我看到了人们将Url.ActionFor放在src =""中的解决方案,但是有了这种解决方案,就没有地方放置我的图像了。

最佳解决方案是什么?

c# .net model-view-controller view controller
3个回答
0
投票

为什么不使用标签修饰图片?

<a href="@Url.Action("actionName", "controller name")"><img src="../../Content/Images/Image.bmp", alt="Alt" /></a> 

不知道为什么要将此插入到src属性中。


0
投票

您认为:

<a class="my-auto" asp-controller="ControlerName" asp-action="ActionName">
    <img src="/path/to/image" alt="logo" class="logo">
</a>

0
投票

将图像包装在链接到您的操作的标签中:

<a href="@Url.Action("Index", "MyController")"><img src="url_of_navbar_image"></a>
© www.soinside.com 2019 - 2024. All rights reserved.