Ajax.ActionLink不会工作,如果确认是假的?工作、Ajax、ActionLink

2023-09-10 21:01:03 作者:个性微信大集合

@Ajax.ActionLink("like", "Like", "Article", new { postId = Model.post.PostId, userName = User.Identity.Name }, new AjaxOptions { OnBegin = "OnBegin" }, new { @class = "like_link" })

function OnBegin()
{
    if( true ) // value from client side. not returning value from server.
    {
        // I dont want to work the link. I want only alert message.
    }
    else
    {
        // Go to controller with parameters.
    }
}

我想是这样上面。 OnBegin不neccesary做到这一点。可能是另一种解决方案。

I want something like above. OnBegin is not neccesary to do it. May be another solutions.

感谢。

推荐答案

OnBegin 应该这样做。简单地返回取决于你是否要执行控制器动作与否:

OnBegin should do it. Simply return true or false depending on whether you want to execute the controller action or not:

function OnBegin() {
    if (true) // value from client side. not returning value from server.
    {
        // I dont want to work the link. I want only alert message.
        alert('alerting some message');
        return false;
    }
    else {
        // Go to controller with parameters.
        return true;
    }
}