ASP.Net MVC 3.0 Ajax.ActionLink Onbegin Function true the execute the action?

人盡茶涼 提交于 2019-12-12 09:11:02

问题


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?


回答1:


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




回答2:


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;
}


来源:https://stackoverflow.com/questions/8056968/asp-net-mvc-3-0-ajax-actionlink-onbegin-function-true-the-execute-the-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!