我在我的MVC 3 Razor应用程序中使用Ajax.Begin Form
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;
}
1 回答
找到了 !
只需要将我的OnBegin属性调整为
我提到的链接ASP.Net MVC 3.0 Ajax.ActionLink Onbegin Function true the execute the action?