In My ASPMVC Code I filled the ViewBag.Contacts variable by use the below code
var contactsGroups = EntityContext.DBContext.TS_GetConfirmedContacts(typeId,AccountId).GroupBy(c=>c.GroupName);
// JSONGroup Custom object
List<JSONGroup> jsonContactsGroups = new List<JSONGroup>();
foreach (var group in contactsGroups)
{
jsonContactsGroups.Add(new JSONGroup
{
GroupName = group.Key,
Objects = new List<object>(group.ToList())
});
}
var result = new JsonResult
{
Data = jsonContactsGroups,
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
ViewBag.Contacts = result;
When I am tried to access the ViewBag.Contacts variable from javascript by this Code
var contactData = '@ViewBag.Contacts';
After debugging the value returned as string [from console]
var contactData = 'System.Web.Mvc.JsonResult';