NickP
NickP

Reputation: 1414

Action link button

I am moving over from VB to C# and am having problems trying to work out an equivalent in C# for the following razor code (which shows an action link as a button)?

@Html.ActionLink("Send Message", "SendCustomerMessage", "SendMessage", 
             New With {.id = currentItem.CustomerId}, New With {.class = "btn"})

Upvotes: 4

Views: 19183

Answers (2)

Chamaququm
Chamaququm

Reputation: 6728

Override

enter image description here

Razor

@Html.ActionLink("LinkText", "Action", "Controller", 
                   new { @id = currentItem.CustomerId }, new { @class = "abc" })

Upvotes: 2

Ufuk Hacıoğulları
Ufuk Hacıoğulları

Reputation: 38468

I'm not familiar with VB but it should work when you create anonymous objects like this:

@Html.ActionLink("Send Message", "SendCustomerMessage", "SendMessage", 
                     new {id = currentItem.CustomerId}, new  { @class = "btn"})

We need @ before class property because class is a reserverd word in C#. You may want to read more about anonymous types.

Upvotes: 6

Related Questions