Copied to clipboard

Flag this post as spam?

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


  • Wilson 14 posts 103 karma points
    Aug 07, 2017 @ 15:05
    Wilson
    0

    How to display json string as list Of record in screen

    I use httpclient in controller to get the data from server. I manage to deserized it to list of object.

    What I want to do is display the data like a data list or data grid in screen. Any recommendations?

  • Tobias Klika 101 posts 570 karma points c-trib
    Aug 08, 2017 @ 09:58
    Tobias Klika
    0

    Where do you want to display it? In the frontend? In the backoffice?

  • Wilson 14 posts 103 karma points
    Aug 08, 2017 @ 10:01
    Wilson
    0

    in the frontend. i means show it in umbraco web page.

    thanks.

  • Tobias Klika 101 posts 570 karma points c-trib
    Aug 08, 2017 @ 15:46
    Tobias Klika
    0

    So if you have your data in List<MyObject> you can either pass it directly to the view or pass it as part of a view model (depends if you need other data in the view too - I would always recommend a view model).

    If you use a view model, create it like this:

    public class MyViewModel
    {
      public List<MyObject> Items { get; set; }
    }
    

    in your controller:

    List<MyObject> items = ...
    MyViewModel vm = new MyViewModel()
    {
      Items = items
    };
    
    return View("MyView", vm);
    

    In your view or partial view:

    @inherits UmbracoViewPage<MyViewModel>
    
    @foreach (var item in Model.Items)
    {
       <p>@item....</p>
    }
    

    So, is this what you are looking for or do you have any additional questions?

Please Sign in or register to post replies

Write your reply to:

Draft