title: Asp.Net MVC - Binding of parameter to model value!
body: <p>This seems like the model binding is causing me issues.</p>
  
  <p>Essentially I have a model called ProductOption and for the purpose of this question it has 2 fields</p>
  
  <blockquote>
    <p>ID (Int) PK
    ProductID (Int) FK</p>
  </blockquote>
  
  <p>I have a standard route set-up</p>
  
  <pre><code>    context.MapRoute(
          "Product_default",
          "Product/{controller}/{action}/{id}",
          new { controller = "Product", action = "Index", id = UrlParameter.Optional }
      );
  </code></pre>
  
  <p>and if the user wants to add an option the URL is,</p>
  
  <blockquote>
    <p>/Product/Options/Add/1</p>
  </blockquote>
  
  <p>in the above URL 1 is the ProductID, I have the following code to return a blank model the the view,</p>
  
  <pre><code>[HttpGet]
  public ActionResult Add(int id)
  {
      return View("Manage", new ProductOptionModel() { ProductID = id });
  }
  </code></pre>
  
  <p>Now in my view I keep a hidden field</p>
  
  <pre><code>&lt;%= Html.HiddenFor(x=&gt;x.ID) %&gt;
  </code></pre>
  
  <p>This is used to determine (on submit) if we are editing or adding a new option. However the Model binder in .net seems to replace .ID (Which was 0 when leaving the above get actionresult) with 1 (or the value of the id parameter in the URL)</p>
  
  <p>How can I stop or work around this?</p>
  
  <p>ViewModel</p>
  
  <pre><code>public class ProductExtraModel
  {
      //Database 
      public int ID { get; set; }
      public string Name { get; set; }
      public int ProductID { get; set; }
  
      public ProductModel Product { get; set; }
  }
  </code></pre>