You must Sign In to post a response.
  • Category: ASP.Net MVC

    Work with JSONresult and ViewBag together


    I am working on 1 page where I need to bind the data in table format.
    I done with it. Below the table / grid, I have buttons "Next" and "Previous.
    Here, I am binding data through JSONResult. I am passing list through it to View.

    In the same method, I have declared one ViewBag variable.
    Its like,

    ViewBag.CurrentPageIndex = 1;
    ViewBag.LastPageIndex = 2;
    objList = objSelfService.GetData(FirstPageIndex, PageSize);
    return Json(objList, JsonRequestBehavior.AllowGet);

    Here, In view, I am not able to get the value of ViewBag.
    I think, it may be because of JSONResult i am using.
    How can I pass or access ViewBag value in View using JSONResult along with my list.
  • #768212

    You can pass those values with JSON result. You can code like below.

    var obj = new { list = objList , CurrentPageIndex = 1, LasPageIndex = 2}
    return Json(obj , JsonRequestBehavior.AllowGet)

    so in javascript you can access these values.

  • Sign In to post your comments