0
<a href="@item.documentId" class="glyphicon glyphicon-remove-circle del-file"></a>
的JavaScript
$(".del-file").click(function() {
alert($(this).attr('href'));
var jsonData = "{'doc':'" + $(this).attr('href') + "'}";
var parent_row = $(this).closest('tr');
$.post('@Url.Action("Delete","Documents")', jsonData)
.success(function (response) {
if (response.result == true) {
$(parent_row).remove();
}
})
.error(function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 500) {
alert('Internal error: ' + jqXHR.responseText);
} else {
alert('Unexpected error.');
}
})
return false;
})
MVC控制器的方法
public JsonResult Delete(string doc)
{
long docId = Helpers.Utility.Instance.getIdAfterDecode(doc);
if (docId <=0)
{
return Json(new { result = "error: Document info was not correct." });
}
bool output = new DocumentsInfoRepository().deleteDocument(docId);
return Json(new { result = output});
}
文檔是ALWA ys null,我錯過了什麼。請指教。謝謝
只是'VAR jsonData = {DOC:$(本).attr( 'href' 屬性)};'(不含引號) –
@StephenMuecke。很快的解決方案。 Thanksss! – Sami