title: Convert Dropdownlist item's value to int
body: <p>I need the value of SelectListItem to be int. </p>
  
  <p>So I pull it of the database, convert it to string in the process and store to listitem's value.</p>
  
  <pre><code>public class BookAdd
  {
  public BookAdd()
  {
  public Book Book { get; set; }
  DataModelContainer db = new DataModelContainer();
  IEnumerable&lt;SelectListItem&gt; items = db.PublisherSet
                 .Select(i =&gt; new SelectListItem
                 {
                   Value = SqlFunctions.StringConvert((double)i.Id), 
                   Text = i.Name
                 });
      }
  }
  </code></pre>
  
  <p>I then need to store the value again as int to Book.PublisherId when selected from dropdownlist. I know the code below is not complete, I figured I need somehow convert the selected item's value to int, how do I do it?</p>
  
  <pre><code>@model Bookshops.Models.BookAdd
  ...
  @Html.DropDownListFor(model =&gt; model.Book.PublisherId, Model.items);
  </code></pre>
  
  <p>And finaly controler:</p>
  
  <pre><code>    public ActionResult Create2()
      {
          var bookAdd = new BookAdd();
          ViewBag.Publisher = bookAdd.items;
          return View(bookAdd);
      }
  
      //
      // POST: /Book/Create
  
      [HttpPost]
      public ActionResult Create2(BookAdd book)
      {
              if (ModelState.IsValid)
              {
                  Book book2 = new Book();
                  book2.Id = book.Book.Id;
                  book2.AuthorId = book.Book.AuthorId;
                  book2.Isbn = book.Book.Isbn;
                  book2.Id = int.Parse(book.Book.PubId);
                  book2.Title = book.Book.Title;
                  book2.YearPublished = book.Book.YearPublished;
  
                  db.BookSet.Add(book2);
                  db.SaveChanges();
              }
              return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>I'm using MVC 3, EF 4.</p>