Lazy loading

In some cases, you have a big amount of data, and the page loading process needs time. A good practice is loading the full page markup first and then loading big data with an additional request to the server. Knockout MVC allows you do it in an easy way.

Imagine that your library contains a large number of books. Let's consider an example with lazy loading of the book list.

The Model will be as follows:

public class BookModel { public string Title { get; set; } public string Author { get; set; } } public class LibraryModel { public bool IsLoaded { get; set; } public List<BookModel> Books { get; set; } public void LoadData() { Books = new List<BookModel>(); Books.Add(new BookModel { Title = "Oliver Twist", Author = "Charles Dickens" }); ...

Get Getting Started with Knockout.js for .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.