Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
693 views
in Technique[技术] by (71.8m points)

css - How do I add a class to an @Html.ActionLink?

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>

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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" })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...