Tangara G

Tangara G

  • NA
  • 298
  • 92.3k

Why the data is not populated ?

Jul 8 2016 10:08 AM
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:
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using BootstrapIntroduction.Models;  
  6. using System.Data.Entity;  
  7.   
  8. namespace BootstrapIntroduction.DAL  
  9. {  
  10.     public class BookInitializer : DropCreateDatabaseIfModelChanges<BookContext>  
  11.     {  
  12.         protected override void Seed(BookContext context)  
  13.         {  
  14.             var author = new Author  
  15.             {  
  16.                 Biography = "...",  
  17.                 FirstName = "Jamie",  
  18.                 LastName = "Munro"  
  19.             };  
  20.   
  21.             var books = new List<Book>  
  22.             {  
  23.                 new Book {  
  24.                     Author = author,  
  25.                     Description = "...",  
  26.                     ImageUrl = "http://ecx.images-amazon.com/images/I/51T%2BWt430bL._AA160_.jpg",  
  27.                     Isbn = "1491914319",  
  28.                     Synopsis = "...",  
  29.                     Title = "Knockout.js: Building Dynamic Client-Side Web Applications"  
  30.                 },  
  31.                 new Book {  
  32.                     Author = author,  
  33.                     Description = "...",  
  34.                     ImageUrl = "http://ecx.images-amazon.com/images/I/51AkFkNeUxL._AA160_.jpg",  
  35.                     Isbn = "1449319548",  
  36.                     Synopsis = "...",  
  37.                     Title = "20 Recipes for Programming PhoneGap: Cross-Platform Mobile Development for Android and iPhone"  
  38.                 },  
  39.                 new Book {  
  40.                     Author = author,  
  41.                     Description = "...",  
  42.                     ImageUrl = "http://ecx.images-amazon.com/images/I/51LpqnDq8-L._AA160_.jpg",  
  43.                     Isbn = "1449309860",  
  44.                     Synopsis = "...",  
  45.                     Title = "20 Recipes for Programming MVC 3: Faster, Smarter Web Development"  
  46.                 },  
  47.                 new Book {  
  48.                     Author = author,  
  49.                     Description = "...",  
  50.                     ImageUrl = "http://ecx.images-amazon.com/images/I/41JC54HEroL._AA160_.jpg",  
  51.                     Isbn = "1460954394",  
  52.                     Synopsis = "...",  
  53.                     Title = "Rapid Application Development With CakePHP"  
  54.                 }  
  55.             };  
  56.   
  57.             books.ForEach(b => context.Books.Add(b));  
  58.   
  59.             context.SaveChanges();  
  60.         }  
  61.     }  
  62. }  
  63.     
 and the index.html under Author folder is
  1. @model IEnumerable<BootstrapIntroduction.Models.Author>  
  2.   
  3. @{  
  4.     ViewBag.Title = "Authors";  
  5. }  
  6.   
  7. <h2>Authors</h2>  
  8.   
  9. <p>  
  10.     @Html.ActionLink("Create New""Create")  
  11. </p>  
  12. <table class="table table-bordered table-striped">  
  13.     <thead>  
  14.         <tr>  
  15.         <th>@Html.DisplayNameFor(model => model.FirstName) </th>  
  16.         <th>@Html.DisplayNameFor(model => model.LastName)  </th>  
  17.         <th>@Html.DisplayNameFor(model => model.Biography) </th>  
  18.         <th>Actions</th>  
  19.     </tr>  
  20.     </thead>  
  21.     <tbody data-bind="foreach: authors">   
  22.     <tr>  
  23.         <td data-bind="text: FirstName"></td>  
  24.         <td data-bind="text: LastName"></td>  
  25.         <td>  
  26.             <a data-bind="attr: {href: '@Url.Action("Details")/' + Id }" class="btn btn-info">Details</a>  
  27.             <a data-bind="attr: {href: '@Url.Action("Edit")/' + Id }" class="btn btn-primary">Edit</a>  
  28.             <a data-bind="attr: {href: '@Url.Action("Delete")/' + Id }" class="btn btn-danger">Delete</a>  
  29.         </td>  
  30.     </tr>  
  31. </table>  
  32.   
  33. @section Scripts {  
  34.   
  35.     <script type= 'text/javascript' src='/Scripts/knockout-3.3.0.js'></script>  
  36.     <script>  
  37.         function ViewModel(authors) {  
  38.             var self = this;  
  39.             self.authors = authors;  
  40.         };  
  41.         var viewModel = new ViewModel(@Html.HtmlConvertToJson(Model)));  
  42.         ko.applyBindings(viewModel);  
  43.     </script>  

 Thank you for your patient and I truly appreciate your helping to a beginner like me.
 

 
 
 
 
 
 
 
 
 
 

Answers (4)