We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

how to make a button with @ Html.ActionLink?

hello, 

I've read the manual several times, I searched in google, Syncfusion the site and could not make a Html.ActionLink work with the button, calling the controller can give me an example?

3 Replies

SS Saranya Sivakumar Syncfusion Team September 23, 2014 09:25 AM UTC

Hi Ezequie,

We would like to let you know that, we cannot directly make the Html.ActionLink to work using button. Since Html.ActionLink returns the anchor tag. So we have to customize CSS style to the anchor tag to look like a button. Else we have to use “@Url.Action(“actionName”,”controllerName”)” in order to redirect to the view page. Both Html.ActionLink and Url.Action will works similarly. Hence we can use Url.Action instead of Html.ActionLink. For your convenience we have prepared the sample based on your requirement. Please download the same in the following location.

Sample Location: Sample

In the above sample we have created the button and binded the click event in the script section. In the click event we have given the Url.Action to redirect to the view page. Please find the following code snippet for more reference.

We have created the button in CSHTML page as follows.

[CSHTML]

<button id="button1">

button>

 

We have initialized the Button and Url.Action in the script section as follows.

[Javascript]

<script type="text/javascript">

    $(document).ready(function () {

        $("#button1").ejButton({

            "click": "onclick",

            text: "Click Here"

        });

    });

    function onclick() {

        document.location = '@Url.Action("Index","Home")';

    }

script>

Please let us know if you have further concern.

Regards,

Saranya.S



ED ezequie da silva daniel September 23, 2014 12:05 PM UTC

Ok, Thanks, solved! 

Regards,

Ezequiel


SS Saranya Sivakumar Syncfusion Team September 24, 2014 04:08 AM UTC

Hi Ezequie,

Thanks for your update.

Please get back to us if you have further concern, we will be happy to help you out.

Regards,

Saranya.S


Loader.
Live Chat Icon For mobile
Up arrow icon