title: ASP.NET MVC 3 Range Validator fails when page is loaded, but text validation works fine
body: <p>When my page loads in "edit" mode, my text fields render correctly, but my numeric fields render with the error validation text visible, even though the value in the field is valid:</p>
  
  <p><img src="https://i.stack.imgur.com/s07DB.jpg" alt="numeric field loads with error text"></p>
  
  <p>My problem is in a more complex project, but I was able to reproduce it in an out-of-the-box MVC 3 application in which I just added these bits.  Why does the numeric field display the error text but the text field is fine when the page loads?</p>
  
  <p>What is going on here?</p>
  
  <p>I have the following for my Model, Controller, and View:</p>
  
  <p>Model:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.ComponentModel.DataAnnotations;
  
  namespace MvcIssues.Models
  {
      public enum Operations
      {
          View = 0,
          Edit = 1
      }
  
      public class ShowsModel
      {
          public Operations Operation { get; set; }
  
          [Display(Name = "Name")]
          [DataType(DataType.Text)]
          [StringLength(10)]
          public string Name { get; set; }
  
          [Display(Name = "Number")]
          [Required]
          [Range(typeof(int), "1", "999")]
          public int Number { get; set; }
      }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using MvcIssues.Models;
  using MvcIssues.Data;
  
  namespace MvcIssues.Controllers
  {
      public class TestController : Controller
      {
          // GET: /Test/Shows
          [AcceptVerbs(HttpVerbs.Get)]
          [ActionName("Shows")]
          [Authorize]
          public ActionResult SelectedShows()
          {
              ShowsData shows = MvcApplication.Shows;
  
              ShowsModel model = new ShowsModel();
  
              model.Operation = Operations.View;
              model.Name = shows.Name;
              model.Number = shows.Number;
  
              return View(model);
          }
  
  
          // POST: /Test/Shows
          [AcceptVerbs(HttpVerbs.Post)]
          [ActionName("Shows")]
          [ValidateInput(false)]
          [Authorize]
          public ActionResult ShowsSubmit(ShowsModel data)
          {
              string name = data.Name;
              int number = data.Number;
  
              ShowsModel model = new ShowsModel();
  
              if (Request.Form.AllKeys.Contains("btnEdit"))
              {
                  ShowsData shows = MvcApplication.Shows;
                  model.Name = shows.Name;
                  model.Number = shows.Number;
  
                  model.Operation = Operations.Edit;
              }
              else if (Request.Form.AllKeys.Contains("btnCancel"))
              {
                  ShowsData shows = MvcApplication.Shows;
  
                  model.Name = shows.Name;
                  model.Number = shows.Number;
  
                  model.Operation = Operations.View;
              }
              else if (Request.Form.AllKeys.Contains("btnSaveEdit"))
              {
                  ShowsData shows = MvcApplication.Shows;
  
                  shows.Name = name;
                  shows.Number = number;
  
                  model.Name = shows.Name;
                  model.Number = shows.Number;
  
                  model.Operation = Operations.View;
              }
  
              return View("Shows", model);
          }
      }
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@model MvcIssues.Models.ShowsModel
  
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;h2&gt;Test Page&lt;/h2&gt;
  
  &lt;div&gt;
      Show = @this.ViewData.Model.Name
      &lt;br /&gt;
      Number = @this.ViewData.Model.Number.ToString()
  &lt;/div&gt;
  
  &lt;hr /&gt;
  
  &lt;div&gt;
      @Html.ValidationSummary(true, "oops!")
  
      @using (Html.BeginForm())
      {
          &lt;div&gt;
  
              Name: @(this.ViewData.Model.Operation == MvcIssues.Models.Operations.View ?
                  Html.TextBoxFor(m =&gt; m.Name, new { disabled = "disabled", maxLength = "20" })
              :
                  Html.TextBoxFor(m =&gt; m.Name))
              @Html.ValidationMessageFor(m =&gt; m.Name)
  
              &lt;br /&gt;
  
              Number: @(this.ViewData.Model.Operation == MvcIssues.Models.Operations.View ?
                  Html.TextBoxFor(m =&gt; m.Number, new { disabled = "disabled" })
              :
                  Html.TextBoxFor(m =&gt; m.Number))
              @Html.ValidationMessageFor(m =&gt; m.Number)
  
          &lt;/div&gt;
  
          &lt;div&gt;
              @switch (this.ViewData.Model.Operation)
              {
                  case MvcIssues.Models.Operations.Edit:
                      &lt;input type="submit" name="btnSaveEdit" value="Save" /&gt;
                      &lt;input type="submit" name="btnCancel" value="Cancel" /&gt;
                      break;
                  case MvcIssues.Models.Operations.View:
                  default:
                      &lt;input type="submit" name="btnEdit" value="Edit" /&gt;
                      break;
              }
          &lt;/div&gt;        
      }
  
  &lt;/div&gt;
  </code></pre>
  
  <p>If anyone can help me it would be much appreciated.  </p>