私はオンビューHTML.ActionLink
です。私がやっていることは$.ajax()
、からの戻り値 true または false をチェックする関数を呼び出すことですanction
。アクションをヒットし、目的の結果の true/false を返します。しかし、問題は false を返すときです。を表示する必要がありalert
、リダイレクトは、true が返された場合にのみ行う必要があります。
アクションリンク:
<%: 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) {
}
});
}
それは常にリダイレクトします..true / falseを返すかどうか..trueを返す場合にのみリダイレクトする必要があります....
私が間違っているところを修正してください..