Category / Section
How to invoke action by button click in ASP.NET MVC ?
1 min read
Description
This knowledge base explains how to invoke action by button click in ASP.NET MVC.
Solution
You can invoke the controller action, using click event to your Syncfusion Button control. In the click event, you can use Url.Action method to invoke the particular action.
HTML
<!--latest CDN for theme file--> <link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/material.css" /> <!--latest CDN for script file--> <script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js"></script>
You can create Button in CSHTML page as follows.
CSHTML
@Html.EJS().Button("element").Content("Click Me").Render()
JAVASCRIPT
document.getElementById("element").addEventListener('click', function () { location.href = '@Url.Action("Index","Home")'; });
In the Url.Action you can specify the Controller name and the Action name. When you click on the Button, it is redirected to the “Index” method in the “Home” controller.