Razor Ajax.BeginForm和OnBegin阻止调用操作
我正在MVC3+Razor应用程序中使用Ajax.Begin表单Razor Ajax.BeginForm和OnBegin阻止调用操作,razor,ajax.beginform,Razor,Ajax.beginform,我正在MVC3+Razor应用程序中使用Ajax.Begin表单 using (Ajax.BeginForm("ActionName", "ControllerName", new AjaxOptions { OnBegin = "ValidateDateFunction('" + @abc.xyz + "')", HttpMethod = "POST", UpdateTargetId = "savebutton" })) { <input type="su
using (Ajax.BeginForm("ActionName", "ControllerName", new AjaxOptions { OnBegin = "ValidateDateFunction('" + @abc.xyz + "')", HttpMethod = "POST", UpdateTargetId = "savebutton" }))
{
<input type="submit" value="Save" />
}
现在使用这个,我希望如果我的条件失败,那么不应该调用操作。但在这两种情况下,我的行为被称为
请帮忙
下面是我实际的验证方法
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 + "')"
我提到的链接
找到了!只是需要将我的OnBegin属性调整为OnBegin=“return ValidateDateFunction”(“+@abc.xyz+”)“链接我引用了您想要传递给它的内容?找到了吗
OnBegin = "return ValidateDateFunction('" + @abc.xyz + "')"