Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lee 1 post 71 karma points
    Sep 26, 2022 @ 11:57
    Lee
    0

    Umbraco 10 Render Grid in ViewComponent

    Hello,

    I have created a Grid inside my Document type, but I am having a hard time rendering it inside a ViewComponent. I am pretty sure I am missing something simple here. Here is my current layout

    My ViewModel

    public class GridViewModel
    {
        public Newtonsoft.Json.Linq.JToken Grid{ get; set; }
    }
    

    Here is my View Component .cs file

    public async Task<IViewComponentResult> InvokeAsync()
    {
        var gridViewModel= new GridViewModel();
        var content = context.Content.GetById(1061);
    
            if (_context.TryGetUmbracoContext(out IUmbracoContext context))
            {
                var grid = content.Value<Newtonsoft.Json.Linq.JToken>("Grid");
    
                gridViewModel.Grid = grid;
            }
            return View(gridViewModel);
        }
    

    And finally my View

    @model Umbraco.Models.ViewModels.Component.GridViewModel
    
    @Html.GetGridHtml(Model, "grid")
    

    If i spit out the Model Grid property I get the Grid Json I'm just not sure how to render it inside a ViewModel

    Hopefully someone can help

    Thanks

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies