Assign ActionLink to jQuery button in MVC

17,881

Solution 1

Based on your comments, you just want to go to the About action in the Home controller on button click, you can do the following and remove the ActionLink:

$(function () {
    $("#Button1").click(function () {
        location.href = '<%= Url.Action("About", "Home") %>';
    });
});

Solution 2

Give the anchor an id:

<%: Html.ActionLink("About", "About", "Home", null, new { id = "Button1"})%>

Using this overload:

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    Object routeValues,
    Object htmlAttributes // <==============
)
Share:
17,881
CoolArchTek
Author by

CoolArchTek

Updated on June 09, 2022

Comments

  • CoolArchTek
    CoolArchTek almost 2 years

    How do I assign ActionLink to a jQuery button in asp.net MVC page.

    <button id="Button1">Click</button>
    
    <%: Html.ActionLink("About", "About", "Home")%>
    
    <script language="javascript" type="text/javascript">
        $(function () {
    
            $("#Button1").button().click(function () {
                return false;
            });
        });
    </script>