问题
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