我有一个HTML.ActionLink
视图。我正在做的是调用$.ajax()
函数来检查从anction
. 它击中动作,返回所需的结果真/假。但问题是当它返回 false 时。我需要显示一个alert
并且重定向应该只在它返回真实的情况下..
动作链接:
<%: Html.ActionLink("Add Race", "AddRace",
new {eventId = Model.EventId, fleetId=Model.SelectedFleet.ID},
new{onclick="return checkFleetAddedandScroing()"}) %>
功能:
function checkFleetAddedandScroing() {
debugger;
$.ajax({
type: "GET",
url: '<%=Url.Action("CheckFleetExists", new {eventId=Model.EventId})%>',
dataType: "json",
cache: false,
success: function (data, textStatus) {
data = eval("(" + data + ")");
if (data == true) {
alert('Ok button clicked');
return true;
}
else {
alert("Cannot delete this fleet becasue either you have already added races to this event or the fleet has used for boat registration.");
return false;
}
}, //success
error: function (req) {
}
});
}
它总是重定向..它是否返回真/假..只有当它返回真时才应该重定向....
请纠正我做错的地方..