ASP.Net MVC 3.0 Ajax.ActionLink Onbegin Function t

2020-07-25 11:12发布

I have a Ajax Action link, which will call a action Method,

In my Ajax Option i have called a Validate function,

If this function returns true,

then only i would want this Action Execute, not sure how i can get this done?

My Ajax ActionLink

Ajax.ActionLink("Renew", "Edit", "Controller", new { id = "<#= ID #>" }, 
new AjaxOptions
                    {
                        OnBegin = "isValidDate",
                        OnSuccess = "DestroyRecreateAccordion",
                        UpdateTargetId = "accordion",
                        InsertionMode = InsertionMode.InsertAfter,
                    }, new { @class = "standard button" })

How can I do this only if isValidDate returns true?

2条回答
乱世女痞
2楼-- · 2020-07-25 11:28

You need to return false on your OnBegin Method

OnBegin = "function(){ return isValidDate(); }", 


function isValidDate() {
    var date = $('#dateid').val()'
    ...check date....
    if(date is valid) return true;
    else return false;
}
查看更多
【Aperson】
3楼-- · 2020-07-25 11:46

AjaxOptions on Action Link

OnBegin="isValidDate"

JavaScript

   function isValidDate() {
       var date = $('#dateid').val()'
       //...check date....
       if(date is valid) return true;
       else return false;
    }

this worked

查看更多
登录 后发表回答