我一直在爲這一段時間打破了我的頭。我有下面的表單,工作正常。MVC jQuery刪除操作不起作用
@using (Html.BeginForm("Edit", "PCLLine", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.ID)
@Html.HiddenFor(model => model.Field)
<div class="small">
@Html.TextBoxFor(model => model.Number, new { onchange = "setEditWBSElementNumber(this," + Model.ID + ")" })
@Html.ValidationMessageFor(model => model.Number)
</div>
<div class="large">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div>
@Html.EditorFor(model => model.NumberTwo)
@Html.ValidationMessageFor(model => model.NumberTwo)
</div>
<div>
@Html.TextBoxFor(model => model.ConcatNumber, new { @id = Model.ID.ToString() + "_WBSElementNumber" })
@Html.ValidationMessageFor(model => model.ConcatNumber)
</div>
<div class="large">
@Html.EditorFor(model => model.Remarks)
@Html.ValidationMessageFor(model => model.Remarks)
</div>
<div>
<input type="submit" class="accept" value="Opslaan" />
</div>
<div>
<input class="folderButton" value="Opties" onclick="pclSubLineDialog()" />
</div>
<div>
<input class="delete" value="Verwijderen" onclick="deleteItem(); return false;" />
</div>
}
這裏的問題在於刪除。它調用該函數,但不能正確執行。它不打我的控制器動作,但與其他控制器動作嘗試它,它的工作:
function deleteItem() {
$.ajax({
url: "PCLLine/Delete",
type: "POST",
data: { id: "@Model.ID" },
dataType: "json",
success: function (data) {
alert('');
}
});
}
而且控制器:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(int pclLineId)
{
try
{
// TODO: Add delete logic here
_pclLineBLL.DeletePCLLine(pclLineId);
return Json(new { success = true });
}
catch
{
return Json(new { success = false });
}
}