Articles in this section
Category / Section

How to invoke action by button click in ASP.NET MVC?

1 min read

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.


Conclusion

I hope you enjoyed learning about how to invoke action by button click.

You can refer to our ASP.NET MVC Button feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET MVC Button example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied