title: MVC3 Html.SelectList - Always see initial value during validation even if selected option has changed
body: <p>I am creating a select list which is populated with enum values:</p>
  
  <pre><code>&lt;%= Html.DropDownListFor(model =&gt; model.OrderStatus, new SelectList(Enum.GetValues(typeof(OrderStatus))))%&gt;
  </code></pre>
  
  <p>I am now performing client-side validation to ensure that OrderStatus is set properly:</p>
  
  <pre><code>[DisplayName("Order Status"), EnsureOrderStatus("ID")]
  public OrderStatus OrderStatus { get; set; }
  
  
  public class EnsureOrderStatus : ValidationAttribute, IClientValidatable
      {
          private readonly string OrderIDPropertyName;
  
          public EnsureOrderStatus(string orderIDPropertyName)
          {
              OrderIDPropertyName = orderIDPropertyName;
          }
  
          protected override ValidationResult IsValid (object value, ValidationContext validationContext)
          {
              ValidationResult validationResult = ValidationResult.Success;
  
              var propertyTestedInfo = validationContext.ObjectType.GetProperty(OrderIDPropertyName);
              if (propertyTestedInfo == null)
              {
                  validationResult = new ValidationResult(string.Format("Unknown property {0}", OrderIDPropertyName));
              }
              else
              {
                  int orderID = (int)propertyTestedInfo.GetValue(validationContext.ObjectInstance, null);
                  OrderStatus orderStatus = (OrderStatus)value;
  
                  if (orderID == 0 &amp;&amp; orderStatus != OrderStatus.Future)
                  {
                      validationResult = new ValidationResult(string.Format("Order must have have an Order Status of Future when being created."));
                  }
              }
  
              return validationResult;
          }
  
          public IEnumerable&lt;ModelClientValidationRule&gt; GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
          {
              var rule = new ModelClientValidationRule
                  {
                      ErrorMessage = ErrorMessage,
                      ValidationType = "ensureorderstatus"
                  };
  
              rule.ValidationParameters["orderid"] = OrderIDPropertyName;
              yield return rule;
          }
      }
  </code></pre>
  
  <p>The value of 'value' inside of IsValid is always the first enum value of OrderStatus. I was wondering if there was other steps which need to be taken to ensure that the selected value of a DropDownList element updates properly.</p>
  
  <p><strong>UPDATED CODE:</strong></p>
  
  <pre><code>//OrderDetailsModel:
  [DisplayName("Order Status"), EnsureOrderStatus("ID")]
  public OrderStatus OrderStatus { get; set; }
  public List&lt;OrderStatusModel&gt; OrderStatusModels = new List&lt;OrderStatusModel&gt;();
  
  public OrderDetailsModel()
  {
      OrderStatusModels.Add(new OrderStatusModel { EnumStatus = OrderStatus.Active, StringStatus = "Active" });
      OrderStatusModels.Add(new OrderStatusModel { EnumStatus = OrderStatus.Completed, StringStatus = "Completed" });
      OrderStatusModels.Add(new OrderStatusModel { EnumStatus = OrderStatus.Future, StringStatus = "Future" });
  }
  
  
  &lt;%= Html.DropDownListFor(model =&gt; model.OrderStatus, new SelectList(Model.OrderStatusModels, "StringStatus", "EnumStatus"))%&gt;
  </code></pre>