How to Use CSS on an HTML.Actionlink in C#

How do I apply a CSS class to Html.ActionLink in ASP.NET MVC?

It is:

<%=Html.ActionLink("Home", "Index", MyRouteValObj, new with {.class = "tab" })%>

In VB.net you set an anonymous type using

new with {.class = "tab" }

and, as other point out, your third parameter should be an object (could be an anonymous type, also).

How to use CSS on an Html.ActionLink in C#

Make sure you are using the proper overload:

<%: Html.ActionLink("Home", "Index", "Home", null, new { @class = "NavLink" })%>
^ ^
routeValues htmlAttributes

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

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

How to add css class to Action link in MVC

You can add class to ActionLink like this

@Html.ActionLink("Edit", "Edit", new { id = item.ClientId }, new { @class = "fa fa-edit" }) 
@Html.ActionLink("Delete", "Delete", new { id = item.ClientId }, new { @class = "fa fa-times" })

Html. ActionLink: Passing CSS class and Id at the same time

So, I tried this to make it work

 <td>@Html.ActionLink("Sprawdź","Details","Home", new { @item.Id }, new {@class = "btn btn-info" })</td>

Created two annonymous classes, the first one passing Id, and second one passing the class. I leave the topic, maybe someone will find this helpful :)

Adding class to ActionLink

You need to add a null parameter before your style, because it refers to routeValues:

@Html.ActionLink("Login", "Login", "Account", null, new { @class = "btn btn-primary btn-lg" }) 

Have a look at it's documentation Here.

How to Add ID to Html.ActionLink - Same as You Would In HTML / CSS

Try this:

@Html.ActionLink("LION TECHNOLOGIES", "Index", "Home", new { area = "" }, new { @class = "navbar-brand", @id = "navbar-text"})

add class to @Html.ActionLink

for reserved words you have to add @

new { @style="padding:2px 10px;", @class = "className" })


Related Topics



Leave a reply



Submit