我正在尝试在 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/