Search results

Add link to a Button in ASP.NET MVC Button control

22 Jul 2021 / 1 minute to read

The appearance of the Button can be changed like a hyperlink by e-link class using cssClass property and link navigation can be handled in Button click event.

In the following example, link is added in Button click event by using window.open() method.

razor
link.cs
Copied to clipboard
@Html.EJS().Button("button").CssClass("e-link").Content("Go to Google").Render()

<style>

button {
  margin: 25px 5px 20px 20px;
}

</style>


<script>

document.getElementById('button').onclick = (): void => {
  window.open("https://www.google.com");
};

</script>
Copied to clipboard
public ActionResult link()
{
    return View();
}