title: POST asp.net web form to Web API
body: <p>I need to post a form in a ASP.NET Web Forms application to a Web API. The method I'm trying to use is <a href="https://msdn.microsoft.com/en-us/library/9w7b4fz7(v=vs.110).aspx" rel="nofollow noreferrer">System.Net.WebClient.UploadValues(String, NameValueCollection)</a></p>
  
  <p>The Web API will do model binding only if the posted form field names match the model properties.</p>
  
  <p>But the rendered form has field names like <code>ctl00$ctl00$mainContent$mainContent$DateOfBirth</code> or <code>ctl00$ctl00$mainContent$mainContent$MA_Address_State</code></p>
  
  <p>So basically the following does not work:</p>
  
  <pre><code>byte[] responseArray = webClient.UploadValues(action, "POST", Request.Form);
  </code></pre>
  
  <p>I guess I could go through all the form controls on client side and convert them to a <code>NameValueCollection</code> of my choice, but is there a better way?</p>