如何将类添加到@Html.ActionLink? [英] How do I add a class to an @Html.ActionLink?

查看:25
本文介绍了如何将类添加到@Html.ActionLink?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 @Html.ActionLink's 我想让它们看起来像按钮.我可以使用 CSS 实现这一点,但前提是我使用 actionlink 的 #ID 来应用 CSS.我想为操作链接分配一个类,但是当我使用下面的代码时,我收到一条错误消息,说我缺少}".

I have two @Html.ActionLink's that I want to make look like buttons. I'm able to make this happen with CSS but only if I use the #ID of the actionlink to apply the CSS. I want to assign a class to the action links but when I do using the code below I get an error saying I have a missing "}".

 @Html.ActionLink("Print PO", "PoReport", new { id = 51970}, 
                 new { id = "PoPrint"} , new { class = "PoClass"})

这是我正在应用的样式:

Here is the Style I am applying:

<style>
 #PoPrint 
{
 border: 4px outset;
 padding: 2px;
 text-decoration: none;
 background-color:lightskyblue;
}
</style>

这行得通,我想我可以将另一个#ID 添加到样式中,但想将样式应用于类.

This works and I suppose I could just add the other #ID to tthe style but would like to apply the style to the Class.

推荐答案

必须使用 @ 字符,因为 class 是 C# 中的关键字.这是 MSDN 文档的链接:http://msdn.microsoft.com/en-us/library/dd492124(v=vs.108).aspx

You have to use the @ character, since class is a keyword in C#. Here's a link to the MSDN documentation: http://msdn.microsoft.com/en-us/library/dd492124(v=vs.108).aspx

@Html.ActionLink("Link Text", "ActionName", 
         new { controller = "MyController", id = 1 }, 
         new { @class = "my-class" })

这篇关于如何将类添加到@Html.ActionLink?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆