我有一个Jquery Post Query。在将请求发送到控制器动作之后,它无法使控制继续进行。实际上,我正在通过按钮ID点击按钮进行此操作。我只是在这里发布代码。请建议我在哪里做错了。
查看代码
$('#Get').click(function () {
ItemNo= "4";
if (ItemNo != "" && ItemNo != '') {
$.post('@Url.Action("CheckStocktake", "Stocktake")', { ItemNo: ItemNo }, function (data) {
if (data == "I") {
$('#ItemNumber').after("<label class='label' id='inoitem' style='color:red;float:right;'> Item No is not exist in the Items table entry.</label>");
e.preventDefault();
return false;
}
else if (data == "S") {
$('#ItemNumber').after("<label class='label' id='inostock' style='color:red;float:right;'> Entered Item No. already exist in Stocktake. Try another.</label>");
e.preventDefault();
return false;
}
else if (data == "F") {
alert("");
return true;
}
});
}
控制器代码
public JsonResult CheckStocktake(string ItemNo)
{
bool ifexist = Db.Items.Any(a => a.ItemNo == ItemNo);
bool stockexist = Db.Stocktakes.Any(b => b.ItemNo == ItemNo);
if (!ifexist)
{
return Json("I", JsonRequestBehavior.AllowGet);
}
else if (stockexist)
{
return Json("S", JsonRequestBehavior.AllowGet);
}
return Json("F", JsonRequestBehavior.AllowGet);
}
答案 0 :(得分:0)
$.each(data, function (index, d)
{
place your if conditions inside this changing data to d.......
}
希望它可能有用,如果没有尝试将你的电话改为下面......
$.getJSON("/Controller/action", { ItemNo: ItemNo }, function (data)
{
$.each(data, function (index, d)
{
if condition here as i mentioned above change data to d
});
});
应该让我知道......发生了什么