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

问题描述

我有两个 @ Html.ActionLink的,我想让模样的按钮。我能够做到这一点与 CSS 但只有当我使用的ActionLink的#ID应用 CSS 。我想指定一个类的动作链接,但是当我使用code下面我得到一个错误,说我有一个丢失的}。

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.

推荐答案

您必须使用 @ 字符,因为类是在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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:05