Thursday, May 31, 2018

Sitecore json method

using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using ISACA.Api.Models.Chapters;
using IsacaDP.Feature.PageContent.Repositories;



....


public ActionResult MemberRenewalJson()
        {
            //XC to do: when sso is ready use chapter id from user profile
            IEnumerable<ChapterSummary> chapters = _chapterLeaderRepository.GetChapters();

            //XC to do: remove constant and use chapter ID from profile
            ChapterSummary chapter = chapters.FirstOrDefault(x => x.ChapterId == "002");

            var serializer = new JavaScriptSerializer();
            var model = serializer.Serialize(chapter);

            return Json(new
            {
                model
            }, JsonRequestBehavior.AllowGet);

            //return Json(new
            //{
            //    Data = model
            //}, JsonRequestBehavior.AllowGet);

            //var result = new JsonResult
            //{
            //    Data = model
            //}, JsonRequestBehavior.AllowGet); ;

            //return result;
        }



Called as http://isacadp_sc.local/api/sitecore/ChapterLeader/MemberRenewalJson


No comments:

Post a Comment