我在 MVC3 + Razor 应用程序中使用 Ajax.Beginform
using (Ajax.BeginForm("ActionName", "ControllerName", new AjaxOptions { OnBegin = "ValidateDateFunction('" + @abc.xyz + "')", HttpMethod = "POST", UpdateTargetId = "savebutton" }))
{
<input type="submit" value="Save" />
}
下面是我的 onBegin 方法的样子。我将一个值传递给此方法,我能够收到适当的警报。
function ValidateDateFunction(id) {
alert(id);
if(some-ConditionUsing-formId)
{
return false;
}
return true;
}
现在使用它,我希望如果我的条件失败,则不应调用操作。但在我的情况下,在这两种情况下,我的行动都会被调用。
请帮忙解决这个问题。
下面是我的实际验证方法
function ValidateDateFunction(fId) {
var first = document.getElementById("startDate" + fId);
var second = document.getElementById("endDate" + fId);
if (first.value == "" && second.value != "") {
alert("Please select both dates");
return false;
}
else if (first.value != "" && second.value == "") {
alert("Please select both dates");
return false;
}
var startDateVal = new Date(first.value);
var endDateVal = new Date(second.value);
if (startDateVal.getTime() > endDateVal.getTime()) {
alert("Error ! The start date is after the end date!");
return false;
}
alert('should not reach here');
return true;
}
找到了 !
只需将我的 OnBegin 属性调整为
OnBegin = "return ValidateDateFunction('" + @abc.xyz + "')"
我提到的链接ASP.Net MVC 3.0 Ajax.ActionLink Onbegin 函数 true 执行操作?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)