0

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).

4

2 回答 2

3

利用

OnBegin = "return ValidateForm(11,55)"

function ValidateForm(a,b) {
    return a<b;
}
于 2012-11-13T09:55:24.043 回答
0

我不确定 CrazyCoderz 的评论是如何关联的,但它是如何关联的。

我发现函数名之后的任何内容都会导致 Ajax OBegin 返回 true。这包括 OnBegin = "ValidateForm()"。[我在括号中的错误]

我现在正在实现一个“解决方法” - 两个之一 - 要么编写我自己的 Ajax 调用,要么从表单的测试输入元素中读取属性以获得我想要的值。所以,感谢 CrazyCoderz 让我走上解决方案的轨道。

于 2012-09-17T08:44:20.053 回答