Controller:-
[HttpPost]
public ActionResult EmailScheduler()
{
long lCustDesignID = 1;
int countProduct = gateWay.TotalCountOfCustomers(lCustDesignID);
ViewBag.ItemCount = countProduct;
return Json(JsonRequestBehavior.AllowGet);
}
View:-
<h4>Number Of Records - <span>@ViewBag.ItemCount</span> </h4>
This controller is called on button click.
From Controller how to get value to View in viewbag.
.
最佳答案
如果EmailScheduler
是ajax调用,那么你不能像你尝试过的那样使用ViewBag
。
您需要像下面这样修改您的代码。
Controller
[HttpPost]
public ActionResult EmailScheduler()
{
long lCustDesignID = 1;
int countProduct = gateWay.TotalCountOfCustomers(lCustDesignID);
return Json(countProduct,JsonRequestBehavior.AllowGet);
}
HTML
<h4>Number Of Records - <span id="spnCount"></span> </h4>
Ajax
$.ajax({
//....
success: function(data){
$('#spnCount').text(data);
}
})
关于jquery - 从 Controller 调用Viewbag数据来查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44235543/