title: ModelBinding with Steve Sandersons BeginCollectionItem
body: <p>I'm using Steve Sandersons <code>BeginCollectionItem</code> extension to help with binding lists of items. This works fine for primitive types. The problem I'm having is that for a custom model binder that I've written I can't see how to generate the full name and index of the item that I'm binding to.</p>
  
  <p>Currently my model binder looks like this:</p>
  
  <pre><code>public class MoneyModelBinder : DefaultModelBinder 
  {
      protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)
      {
          var valueResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName + ".Amount");
  
          if (valueResult != null)
          {
              var value = valueResult.AttemptedValue;
              var currencyCode = bindingContext.ValueProvider.GetValue(bindingContext.ModelName + ".Iso3LetterCode").AttemptedValue;
  
              var money = (Money) bindingContext.Model;
  
              Money parsedValue;
              if (String.IsNullOrEmpty(value))
              {
                  money.Amount = null;
                  return;
              }
  
              var currency = Currency.FromIso3LetterCode(currencyCode);
  
              if (!Money.TryParse(value, currency, out parsedValue))
              {
                  bindingContext.ModelState.AddModelError("Amount", string.Format("Unable to parse {0} as money", value));
              }
              else
              {
                  money.Amount = parsedValue.Amount;
                  money.Currency = parsedValue.Currency;
              }
          }
          else
          {
              base.OnModelUpdated(controllerContext, bindingContext);
          }
      }
  }
  </code></pre>
  
  <p>My ViewModel Lokks like this (some propertis omitted for clarity):</p>
  
  <pre><code>public class EditFeeEarningCapacityViewModel
  {
  
      public List&lt;FeeEarner&gt; FeeEarners { get; set; }
  
      public class FeeEarner
      {
          public Money AverageChargeOutRate { get; set; }
      }
  }
  </code></pre>
  
  <p>My Edit Template for the Money type looks like this:</p>
  
  <pre><code>@model Core.Money
  @{
      int decimalPlaces;
      if(!int.TryParse(string.Format("{0}", ViewData["DecimalPlaces"]), out decimalPlaces))
      {
          decimalPlaces = 0;
      }
  }
  &lt;div class="input-prepend"&gt;
      &lt;span class="add-on"&gt;@Model.Currency.Symbol&lt;/span&gt;@Html.TextBoxFor(m =&gt; m.Amount,
                                                                  new
                                                                  {
                                                                      placeholder = string.Format("{0}", Model.Currency),
                                                                      @class = "input-mini",
                                                                      Value = String.Format("{0:n" + decimalPlaces + "}", Model.Amount)
                                                                  })
  &lt;/div&gt;
  @Html.HiddenFor(x =&gt; x.Iso3LetterCode)
  </code></pre>
  
  <p>For a form that has post values like this:</p>
  
  <pre><code>FeeEarners.index    3fa91d09-0617-4bea-ae3f-d84862be8c04
  
  FeeEarners[3fa91d09-0617-4bea-ae3f-d84862be8c04].feeEarner.AverageChargeOutRate.Amount  500
  FeeEarners[3fa91d09-0617-4bea-ae3f-d84862be8c04].feeEarner.AverageChargeOutRate.Iso3LetterCode  GBP
  </code></pre>
  
  <p>I can't see how to detect the index of the item or the property name that I'm binding to. So essentially, how do I find the index of the item I'm trying to bind to and the name of the property that I'm trying to bind the data from?</p>