My problem now is that the hard coded data is not being populated.
And I'd like to know why.
In this class - BookInitializer, the author has hard-coded an Author name Jamie Munro:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using BootstrapIntroduction.Models;
- using System.Data.Entity;
-
- namespace BootstrapIntroduction.DAL
- {
- public class BookInitializer : DropCreateDatabaseIfModelChanges<BookContext>
- {
- protected override void Seed(BookContext context)
- {
- var author = new Author
- {
- Biography = "...",
- FirstName = "Jamie",
- LastName = "Munro"
- };
-
- var books = new List<Book>
- {
- new Book {
- Author = author,
- Description = "...",
- ImageUrl = "http://ecx.images-amazon.com/images/I/51T%2BWt430bL._AA160_.jpg",
- Isbn = "1491914319",
- Synopsis = "...",
- Title = "Knockout.js: Building Dynamic Client-Side Web Applications"
- },
- new Book {
- Author = author,
- Description = "...",
- ImageUrl = "http://ecx.images-amazon.com/images/I/51AkFkNeUxL._AA160_.jpg",
- Isbn = "1449319548",
- Synopsis = "...",
- Title = "20 Recipes for Programming PhoneGap: Cross-Platform Mobile Development for Android and iPhone"
- },
- new Book {
- Author = author,
- Description = "...",
- ImageUrl = "http://ecx.images-amazon.com/images/I/51LpqnDq8-L._AA160_.jpg",
- Isbn = "1449309860",
- Synopsis = "...",
- Title = "20 Recipes for Programming MVC 3: Faster, Smarter Web Development"
- },
- new Book {
- Author = author,
- Description = "...",
- ImageUrl = "http://ecx.images-amazon.com/images/I/41JC54HEroL._AA160_.jpg",
- Isbn = "1460954394",
- Synopsis = "...",
- Title = "Rapid Application Development With CakePHP"
- }
- };
-
- books.ForEach(b => context.Books.Add(b));
-
- context.SaveChanges();
- }
- }
- }
-
and the index.html under Author folder is
- @model IEnumerable<BootstrapIntroduction.Models.Author>
-
- @{
- ViewBag.Title = "Authors";
- }
-
- <h2>Authors</h2>
-
- <p>
- @Html.ActionLink("Create New", "Create")
- </p>
- <table class="table table-bordered table-striped">
- <thead>
- <tr>
- <th>@Html.DisplayNameFor(model => model.FirstName) </th>
- <th>@Html.DisplayNameFor(model => model.LastName) </th>
- <th>@Html.DisplayNameFor(model => model.Biography) </th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody data-bind="foreach: authors">
- <tr>
- <td data-bind="text: FirstName"></td>
- <td data-bind="text: LastName"></td>
- <td>
- <a data-bind="attr: {href: '@Url.Action("Details")/' + Id }" class="btn btn-info">Details</a>
- <a data-bind="attr: {href: '@Url.Action("Edit")/' + Id }" class="btn btn-primary">Edit</a>
- <a data-bind="attr: {href: '@Url.Action("Delete")/' + Id }" class="btn btn-danger">Delete</a>
- </td>
- </tr>
- </table>
-
- @section Scripts {
-
- <script type= 'text/javascript' src='/Scripts/knockout-3.3.0.js'></script>
- <script>
- function ViewModel(authors) {
- var self = this;
- self.authors = authors;
- };
- var viewModel = new ViewModel(@Html.HtmlConvertToJson(Model)));
- ko.applyBindings(viewModel);
- </script>
- }
Thank you for your patient and I truly appreciate your helping to a beginner like me.