title: Pass Url Parameters to Action by Model in ASP.NET MVC 4
body: <p>I want to assign my url parameters to Model properties, passed as a parameter to the associated Action. For example;</p>
  
  <p>Say, my url is  <a href="http://www.example.com/Item/Index?color=red&amp;size=50" rel="nofollow">http://www.example.com/Item/Index?color=red&amp;size=50</a></p>
  
  <p>My action inside the controller is like below:</p>
  
  <pre><code>public class ItemController : Controller
  {
      public ActionResult Index(MyModel myModel)
      {
          //
  
          return View(myModel);
      }
  }
  </code></pre>
  
  <p>I want to configure the model or whatever necessary so that my model takes the color and size as field values. The following didn't work:</p>
  
  <pre><code>public class MyModel 
  {
      [Display(Name = "color")]
      public string Color{ get; set; }
  
      [Display(Name = "size")]
      public string Size{ get; set; }
  }
  </code></pre>
  
  <p>What would be the correct way to solve the problem?</p>
  
  <p>Thanks for any suggestion.</p>
  
  <h2>Update</h2>
  
  <p>Well, yes! The code above would work correctly, because Url parameter names are the same as model property names. I should explain my problem exactly as I encounter for the next time, sorry.</p>
  
  <p>I must correct a part of my question to make it clear. The url should have been: <a href="http://www.example.com/Item/Index?c=red&amp;s=50" rel="nofollow">http://www.example.com/Item/Index?c=red&amp;s=50</a> to detect the problem.</p>
  
  <p>If the url is like that, the code would not work. Because Url parameters don't have the same name as Model properties.</p>
  
  <p>Updated model is below:</p>
  
  <pre><code>public class MyModel 
  {
      [Display(Name = "c")]
      public string Color{ get; set; }
  
      [Display(Name = "s")]
      public string Size{ get; set; }
  }
  </code></pre>