We are using DXA, Razor views with Web Components.
For Menu (see below) there will be also JSON format needed in the interface.
Sample is assigning JSON string to attribute site-menu.
Best way to do it?
Generate the Json in the Razor view.
Performance impact?Prepare new property in model with output for 'site-menu'. Deserialize that with HTML.Raw the view. I saw it contains text with 'alt' it could be wrong here.
Can make a JObject in the model.
try { result = new JObject( new JProperty("items", new JArray( from item in this.Items select new JObject( new JProperty("id", item.DataTaId), new JProperty("title", this.Title), new JProperty("url", item.Link), new JProperty("overviewLink", item.Title), new JProperty("active", false), new JProperty("expanded", false), new JProperty("subItems", new JArray( from subitem in item.Items select new JObject( new JProperty("id", subitem.DataTaId), new JProperty("title", subitem.Title), new JProperty("url", subitem.Link), new JProperty("active", false)) )))))); } catch (Exception ex) { } var resultstr = result.ToString(); return resultstr;
Seperate JSON file (and include that if possible).
JSON string should be generated something like this.
<bgl-main-nav slot="mainMenu"
site-menu='{"items":[{"id":"myId1000","title":"Home","url":"/home","active":false,"iconName":"home"},
{"id":"myId2000","title":"Level 1","url":"/level1","active":false},
{"id":"myId3000","title":"Level 1","url":"/level1","active":false,"overviewLink":"Description of the subhome page of level1","expanded":false,
"subItems":[
{"id":"myId3001","title":"Level 2 item 1","url":"/level1/level2item1","active":false},
{"id":"myId3002","title":"Level 2 item 2","url":"/level1/level2item2","active":false}]}],
"extraItems":[{"id":"myIdabdc","title":"Customservice","url":"/service","active":false,"iconName":"support"}]}'>
</bgl-main-nav>
JsonResult
). See, for example,NavigationController.SiteMapJson
: github.com/sdl/dxa-web-application-dotnet/blob/master/…