title: Retrieving data from view, should I use model binder?
body: <p>I am a bit lost here as I have not really looked at model binders so if possible, can one advise me if I am actually thinking about my problem correctly... :) and if my code is way of, please advise...</p>
  
  <p>1 -I have a DTO class which contains 'custom fields' each with a name and other properties i.e.:</p>
  
  <pre><code>Public Class CustomFields
  {
   public string Name {get;set;}
   public string Description {get;set;}
   public string FieldType {get;set;}
   public string Value {get;set;}
  }
  </code></pre>
  
  <p>2- Within my repo/business layer I am setting the values and returning ICollection for the view to render</p>
  
  <p>3- the view uses a foreach to display fields</p>
  
  <pre><code>&lt;% foreach (var item in Model) {%&gt;
     &lt;div class="editor-label"&gt;
        &lt;%= Html.Label(item.Name) %&gt;
     &lt;/div&gt;
     &lt;div class="editor-field"&gt;
        &lt;%= Html.TextBox(item.Name, item.Value)%&gt;
     &lt;/div&gt;
  &lt;% } %&gt;
  </code></pre>
  
  <p>Question: What is the best way to retrieve the result via a post? If there are errors I need to send back the errors to the view...</p>
  
  <p>NOTE: What I did--></p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult Index([ModelBinder(typeof(CustomModelBinder))] ICollection&lt;CustomFields&gt; Fields)
  {
  //code here...
  }
  </code></pre>
  
  <p>Custom Model binder gets values from form collection and transforms in into the correct type- is this correct? The best way to do this? I get the feeling I overcomplicated things...</p>
  
  <pre><code>public class CustomModelBinder : IModelBinder
  {
   public object BindModel(ControllerContext controllerContext, 
   ModelBindingContext    bindingContext)
   {
  
    var fields = new List&lt;CustomFields&gt;();
  
    var formCollection = new FormCollection(controllerContext.HttpContext.Request.Form);
  
    foreach (string _key in formCollection)
    {
      if (_key.Contains("_RequestVerificationToken"))
           break;
  
      fields.Add(new CustomFields { Name = _key, 
      Value = formCollection.GetValue(_key).AttemptedValue });
    }
    return fields;
   }
  }
  </code></pre>