Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Send data from MVC to KnockoutJS an show in HTML

Send data from MVC to KnockoutJS an show in HTML

Scheduled Pinned Locked Moved C#
javascripthtmlasp-netdatabasetools
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DPaul1994
    wrote on last edited by
    #1

    I have created a list in MVC which looks like this:

    var countries = new List();

            countries.Add(new Countries() { Id = 1, Mainland = "a", Name = "a" });
            countries.Add(new Countries() { Id = 1, Mainland = "b", Name = "b" });
            countries.Add(new Countries() { Id = 1, Mainland = "c", Name = "c" });
            countries.Add(new Countries() { Id = 1, Mainland = "d", Name = "d" });
            countries.Add(new Countries() { Id = 1, Mainland = "e", Name = "e" });
    
            return View(countries);
    

    That is my Index page. Now, I want to retrieve that list in a js script which, for now, looks like this (this works):

    <script>
    var mainViewModel = {
    countries: ko.observableArray([]),
    initialize: function (model) {
    console.log(model)
    }
    };
    mainViewModel.initialize(@Html.Raw(Json.Encode(Model)));
    ko.applyBindings(mainViewModel);
    </script>

    But now, I want to show those objects in html and I don't really know how do to that. Can anybody help me?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups