Knockout MVC supports a large number of different methods that allow you to write the whole application in pure C# without any line of JavaScript code. However, sometimes we need to write some JavaScript code.
For example, say we want to create a button with the click logic that a title of each book should be enclosed in quotes. If the quote is already set at the beginning or end of the book title, we shouldn't add it again. Also, we will implement this logic in JavaScript on the client side.
The Model will be as follows:
public class BookModel { public string Title { get; set; } public string Author { get; set; } } public class LibraryModel { public List<BookModel> Books { get; set; } }
The Controller will be as follows:
public class LibraryController : KnockoutController { public ActionResult Index() { var model = new LibraryModel { Books = new List<BookModel> { new BookModel { Title = "Oliver Twist", Author = "Charles Dickens...