I am using Ajax.BeginForm and wish to pass in parameters to the function called with OnBegin. The following are two code snippets.
new AjaxOptions
{
HttpMethod = "POST",
UpdateTargetId = "DataEntrySummary",
OnBegin = "ValidateForm(11,55)"
}
function ValidateForm(minAge, maxAge) {return false;}
The parameters are passed in correctly to the ValidateForm function but the function always returns true.
If I take the parameters out and use
OnBegin = "ValidateForm()"
function ValidateForm() {return false;}
It works perfectly and returns false. Am I missing something or are parameters not allowed here or …
Puzzled of Oxford – thanks in advance.
PS – I cannot use C# Attributes and Unobtrusive validation for very good reasons (these are code snippets).
I’m not sure how the comment from CrazyCoderz relates, but it is linked some how.
What I have found is that anything after the the function name causes the Ajax OBegin to return true. This includes OnBegin = “ValidateForm()”. [My error above on the brackets]
I am now implementing a ‘work around’ – one of two – either write my own Ajax call or read the attributes from the test input element of the form to get the values I want. So, thanks CrazyCoderz for putting me on the track to a solution.