c# - 在 ActionLink 中使用 ASP.NET MVC、Razor 页面的图标

标签 c# asp.net css asp.net-mvc razor

我正在尝试在 Razor 代码中的 actionLink 中打印图标,但它没有发生...我将 actionLink 与 action-Name 一起使用,将 Controller 与该类一起使用,并在 css 中使用此类来打印图标...我不知道不知道我哪里做错了???

我在页面源代码中收到以下行;

 <a class="CreateNewEntry_Icon" href="/Qualification/CreateNewFreeZone?Length=13">New FreeZone</a>

我的代码

public ActionResult CreateNewFreeZone()
    {
        return PartialView("Partial_CreateNewFreeZone");
    }


@Html.ActionLink("New FreeZone", "CreateNewFreeZone", "Qualification", new { @class = "CreateNewEntry_Icon" })

CSS:

.CreateNewEntry_Icon {
    width:24px;
    height:24px;
    background:url("~/ImagesAndIcons/Icons/Add_New.png") no-repeat;

}

最佳答案

您需要这个:

@Html.ActionLink("New FreeZone", "CreateNewFreeZone", "Qualification", null, new { @class = "CreateNewEntry_Icon" })

您的原始版本是将类传递给routeValues而不是htmlAttributes参数。

添加额外参数(本例中为 null)会导致调用正确的重载,该重载将 htmlAttributes 作为最后一个参数。

关于c# - 在 ActionLink 中使用 ASP.NET MVC、Razor 页面的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21232385/

相关文章:

mysql - 无法加载文件或程序集 'MySql.Data, Version=6.8.3.0"或其依赖项之一。该系统找不到指定的文件

javascript - 使用 JavaScript 将字节数组显示为图像

c# - 按进程获取文件名

c# - 为什么零长度的 stackalloc 会让 C# 编译器乐于允许有条件的 stackallocs?

javascript - 保留jquery粘贴格式

JQuery 移动按钮 : how to enable the blinking effect when overriding a theme?

css - 多重响应声明的性能影响

c# - 带 iPad 的 MVC.NET 2

c# - 用于 URL 验证的正则表达式

html - 表格单元格中的图像未按比例缩小 : using ie8/7