私はかなり新しいですMVC
。を使用してwithパラメータをajax
呼び出す必要があります。私はこれを渡すことができません。Action
html.Action()
他のMVC初心者にも役立つことを願っています。
HTML:
<%: Html.ActionLink("Add Race", "AddRace",
new {eventId = Model.EventId, fleetId=Model.SelectedFleet.ID},
new{@onclick=string.Format("return checkFleetAddedandScroing()")}) %>
Jquery:
function checkFleetAddedandScroing() {
debugger;
$.ajax({
type: "GET",
url: '<%=Url.Action("CheckFleetExists")%>',
dataType: "json",
cache: false,
success: function (data, textStatus) {
data = eval("(" + data + ")");
if (data == true) {
return true;
}
else {
alert("Cannot Add race becasue you have not yet added any fleets and fleet scoring is checked.");
return false;
}
}, //success
error: function (req) {
}
});
}
アクション:
public JsonResult CheckFleetExists(Guid fleetId )
{
bool exists = false;
try
{
exists = !db.Races.Any(r => r.FleetID == fleetId);
}
catch
{
}
return Json(exists, JsonRequestBehavior.AllowGet);
}
fleetid
にあるアクションに渡す必要がありModel.SelectedFleet.ID
ます。ページのどこかで使用されています。しかし、どういうわけかそれを使用することはできません。
私が間違っているところを提案してください...