title: How to pass IEnumerable list to view
body: <p>Again I want to ask some question about to how to make and pass IEnumerable list?</p>
  
  <p><strong>My Controller:</strong></p>
  
  <pre><code>public class BookController : Controller
  {
     // GET: Book
      public ActionResult Index()
      {
          BookModel viewBookList = new BookModel();
          viewBookList.ViewBookListing(); // viewBookList.ViewBookListing() 
                                          // pass the model values in 
                                          // ViewBookListing method which is located into my bookmodel
          return View(viewBookList);
      }
  }
  </code></pre>
  
  <p>My Model:</p>
  
  <pre><code>  namespace myWeb.Models
    {
          public class BookModel
          {
              public List&lt;BookModel&gt; showAllBooks = new List&lt;BookModel&gt;();
              // *other properties*
   public DataTable viewAllBooks()
          {
              try
              {
                  Connection viewAll = new Connection();
                  viewAll.cmdType = CommandType.StoredProcedure;
                  viewAll.SQL = "insertSelectUpdateDeleteBooks";
                  viewAll.ParamAndValue = new string[,]
                  {
                  {"@bookid", "" },
                  {"@authorid", "" },
                  {"@bookcatid", "" },
                  {"@booktitle", ""},
                  {"@isbn", ""},
                  {"@pubplace", "" },
                  {"@pubdate", "" },
                  {"@bookphoto", "" },
                  {"@statementtype", "Select" }
                  };
                  return viewAll.GetData();
              }
              catch (Exception)
              {
                  throw;
              }
     }
  </code></pre>
  
  <p>return viewAll.GetData(); this GetData get the data or records from my Data Access Layer</p>
  
  <pre><code>        public void ViewBookListing()
          {
              List&lt;BookModel&gt; showAllBooks = new List&lt;BookModel&gt;();
              DataTable dt = this.viewAllBooks();
              if (dt != null)
              {
                  if (dt.Rows.Count &gt; 0)
                  {
                      foreach (DataRow row in dt.Rows)
                      {
                          showAllBooks.Add(new BookModel()
                          {
                              qty = int.Parse(row["Quantity"].ToString()),
                              bookTittle = row["bookTitle"].ToString(),
                              authorName = row["Author"].ToString(),
                              ISBN = row["ISBN"].ToString(),
                              pubPlace = row["pubPlace"].ToString(),
                              pubDate = DateTime.Parse(row["pubDate"].ToString()),
                              DDC = row["DDC"].ToString(),
                              edition = row["edition"].ToString(),
                              volume = row["volume"].ToString(),
                              CategoryName = row["Category"].ToString()
  
                          });
                      }
                  }
              }
              this.showAllBooks = showAllBooks;
          }
      }
  }
  </code></pre>
  
  <p>Here is my view page or index . I don't like this kind of passing the data into view, and i wanted to pass the model data or data using <code>IEnumerable</code> but the problem is, i don't know how to do it. </p>
  
  <pre><code>@using myWeb.Models;
  @model BookModel
  @{
      ViewBag.Title = "Index";
  }
  
  @foreach(myWeb.Models.BookModel item in Model.showAllBooks)
  {
          &lt;tr&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(Model =&gt; item.bookTittle)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(Model =&gt; item.authorName)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(Model =&gt; item.ISBN)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(Model =&gt; item.CategoryName)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(Model =&gt; item.DDC)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(Model =&gt; item.pubPlace)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(Model =&gt; item.pubDate)&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;
                  @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
                  @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
                  @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
              &lt;/td&gt;
          &lt;/tr&gt;
  }
  </code></pre>