How to render @html.actionlink as a button in MVC in Razor

How to render  @HTML.Actionlink  in MVC and using it as a button

Background of @HTML.ACTIONLINK in MVC

The easiest way to render an HTML link in is to use the HTML.ActionLink() helper.

With MVC, the Html.ActionLink() does not link to a view. It creates a link to a controller action.

Razor Syntax:

@Html.ActionLink(“About this Website”, “About”)

ASP Syntax:

<%=Html.ActionLink(“About this Website”, “About”)%>

The first parameter is the link text, and the second parameter is the name of the controller action.

The Html.ActionLink() helper above, outputs the following HTML:

<a href=”/Home/About”>About this Website</a>

 

 

When using  @html.actionlink it normally renders it like a hyperlink. But there is a simple way to render it as a button.

 

Simple example of  @HTML.Actionlink

@Html.ActionLink("Register,"Register")

 

and it will render it as a  Hyperlink

 

 

How to render  @HTML.Actionlink as a button

 

I am using Boostrap so I have the CSS class called “btn” available. Otherwise you can use your own CSS which can create a button

 

 Here is your Answer below

C# Syntax

@Html.ActionLink("Register", "Register" ,null,  new { @class = "btn" })

 

VB.NET Syntax

@Html.ActionLink("Register", "Register" ,null,  new  with {.class = "btn" })   



the null is for the Routevalues ( in the example we are using any route values hence null)

 

Hope this helps you