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

I have an Ajax Action link that will call an action method

In my Ajax option, I called the Validate function,

If this function returns true,

then only I would like this Action Execute, not sure how I can do this?

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 to do this only if isValidDate returns true?

+2
source share
2 answers

AjaxOptions in Action Link

 OnBegin="isValidDate" 

Javascript

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

it worked

+6
source

You need to return false in your OnBegin method

 OnBegin = "function(){ return isValidDate(); }", function isValidDate() { var date = $('#dateid').val()' ...check date.... if(date is valid) return true; else return false; } 
+2
source

All Articles