从控制器调用 Viewbag Data 进行查看
Calling Viewbag Data from controller to view
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
。
您需要像下面这样修改您的代码。
控制器
[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);
}
})
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
。
您需要像下面这样修改您的代码。
控制器
[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);
}
})