title: MVC 4 Pass Object
body: <p>In my project I have a model </p>
  
  <pre><code>      Product (int int, String description, decimal price)
  </code></pre>
  
  <p>I also have another model </p>
  
  <pre><code>       Order (int id, virtual Product product, String customerName)
  </code></pre>
  
  <p>By adding the virtual before product, the product is a foreign key.
  I want to be able to place an order but how can I pass the objects product to the form of placing an order.</p>
  
  <p>Lets say the user first selects a product from a list by clicking on a button buy, after that he has to enter his name (to keep it simple).
  How should I add the product to the enter your name form ?</p>
  
  <p>I tried to add it manualy to my post handler (from the add name form after selecting a product) by using "</p>
  
  <pre><code>    [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create(Order order)
      {
          order.ConnectedProduct = db.Products.Find(1);
          if (ModelState.IsValid)
          {
              db.Orders.Add(order); 
              db.SaveChanges();
              return RedirectToAction("Index");
          }
  
          return View(order);
      }
  </code></pre>
  
  <p>but this still will return the field ConnectedProduct is required. (debbuging shows there is a product selected)</p>