我很陌生MVC
。我需要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()")}) %>
查询:
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
. 它在页面上的某个地方使用。但我无法以某种方式使用它..
请建议我在哪里做错了......