How to create a custom helper for Ajax.ActionLink

I want to create an assistant that works like . I am creating an assistant to do this with some changes: Ajax.ActionLink

@helper AjaxLink(string innerhtml, string href, string targetId)
{
    if (!string.IsNullOrEmpty(innerhtml))
    {
        if (href.Trim() == "#")
        {
            <a href="@(href)">
                @MvcHtmlString.Create(innerhtml)
            </a>
        }
        else
        {
            <a href="@(href)" data-ajax-update="#@(targetId)" data-ajax-mode="replace">
                @MvcHtmlString.Create(innerhtml)
            </a>
        }

    }
}

My assistant will create a link like:

<a href="ItemRegister?testTypeId=1" data-ajax-update="#pageId" data-ajax-mode="replace">
     <i class="fa fa-sign-out"><span style="right: -47px;" class="icon-bg bg-orange"></span></i><span>Register </span>
</a>

But that will not work! It refreshes the page instead of the target.

+4
source share
1 answer

You must put the attribute data-ajaxin the tags <a>:

<a href="@(href)" data-ajax-update="#@(targetId)" data-ajax-mode="replace" data-ajax="true">
       @MvcHtmlString.Create(innerhtml)
</a>
+1
source

All Articles