我想通过返回计数的 Jquery 从视图中调用我的控制器。在调试结果变量时返回未定义。请有人更正我的代码。
看法:
<script type="text/javascript">
$(function () {
$('.icon-delete').click(function () {
debugger;
var v = 'e8a6bdf4-1da6-41e0-8423-86ffacf71703';
var result= GetCollectionCount(v);
var answer = confirm('Do you want to delete this record?');
if (answer) {
$.post(this.href, function () {
window.location.reload(); //Callback
});
return false;
}
return false;
});
});
function GetCollectionCount(id) {
$.ajax({
type: 'POST',
contentType: "application/json;charset=utf-8",
url: '/AdminNew/CollectionCount',
dataType: 'json',
data: { "id": id },
//traditional: true,
success: function (ajaxresult) {
//alert(ajaxresult);
return ajaxresult;
},
failure: function (ajaxresult, status) {
console.log(ajaxresult)
}
});
}