How to invoke action by button click in ASP.NET MVC?
You can invoke the controller action by Button using click event to your Syncfusion ASP.NET MVC Button control. In the click event, you can use Url.Action method to invoke the particular action.
To include the Syncfusion components, add the necessary script and theme files in the <head> section as illustrated in the following code example.
HTML
<!--latest CDN for theme file--> <link href="https://cdn.syncfusion.com/js/web/flat-azure/ej.web.all-latest.min.css" rel="stylesheet" type="text/css" /> <!--CDN for JQuery script file--> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js" type="text/javascript"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/globalize/0.1.1/globalize.min.js"></script> <!--latest cdn for script file--> <script src="https://cdn.syncfusion.com/js/web/ej.web.all-latest.min.js"></script> <!--latest CDN for Unobtrusive JS file--> <script src="https://cdn.syncfusion.com/js/web/ej.unobtrusive-latest.min.js"></script>
You can create Button in CSHTML page as follows.
CSHTML
@Html.EJ().Button("Login").Text("Log in").Type(ButtonType.Button).ClientSideEvents(e=>e.Click("onclick"))
You can write the Url.Action for the Button click event in the script section as follows.
JavaScript
function onclick() { location.href = '@Url.Action("Index","Home")'; }
In the Url.Action you can specify the Controller name and the Action name. Finally, when you click on the Button, the click event is triggered and redirected to the corresponding method in a specified controller. Here, when you click on the Button it is redirected to the “Index” method in the “Home” controller.