title: How to Validate Single Item in a list
body: <p>I have a Model that is shaped like this:</p>
  
  <pre><code>public class GlobalSettingsViewModel
  {
     public List&lt;SettingViewModel&gt; Settings{ get;set;}
  }
  
  public class SettingViewModel 
  {
     public string Name{ get;set;}
     [Range(0,100)]
     public decimal SettingValue{ get;set;}
  }
  </code></pre>
  
  <p>My view calls <code>Html.RenderPartial("SettingView")</code> for each SettingViewModel.</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;SettingViewModel&gt;" %&gt;
  &lt;% using (Html.BeginForm("Save", "GlobalSettings", FormMethod.Post))
     { %&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td width="150px"&gt;
              &lt;%= Html.DisplayFor(m=&gt;m.Name) %&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;%= Html.TextBoxFor(m=&gt;m.SettingValue) %&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type="submit" value="Save" class="uiButton" /&gt;
              &lt;%=Html.ValidationMessageFor(m=&gt;m.SettingValue) %&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
     &lt;%} %&gt;
  </code></pre>
  
  <p>Each <code>SettingView</code> renders a form which posts back to a Save action.</p>
  
  <p>The <code>SettingViewModel</code> is correctly rehydrated from the form and the validation correctly determines when an out or range value is generated.</p>
  
  <p>I returned the original <code>Index</code> view with the full <code>GlobalSettingsViewModel</code> it requires.  </p>
  
  <p>However, when the page renders <strong>every</strong> Validator for SettingValue shows it's error message instead of just the textbox with the incorrect value?</p>
  
  <p>What is the correct way for performing server side validation on a <code>PartialView</code> when it is page of a collection of items?</p>
  
  <hr>
  
  <h2>UPDATE</h2>
  
  <p>So here's what I have....it seems a little odd but seems to work..</p>
  
  <p>I can save a single setting at a time and show validation errors when they occur.  But the weird way in which I save by using a partial model seems a little odd.</p>
  
  <p>Index.aspx</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MVC.Master" Inherits="System.Web.Mvc.ViewPage&lt;GlobalSettingsViewModel&gt;" %&gt;
  &lt;fieldset style="margin: 5px; width: 350px;"&gt;
          &lt;legend&gt;Global System Settings&lt;/legend&gt;
          &lt;div&gt;
              &lt;%= Html.EditorFor(m =&gt; Model.Settings)%&gt;
          &lt;/div&gt;
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>SettingViewModel.ascx</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;SettingViewModel&gt;" %&gt;
  &lt;% using (Html.BeginForm("Save", "GlobalSettings", FormMethod.Post))
     { %&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td width="150px"&gt;
              &lt;%= Model.Name %&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;%= Html.TextBoxFor(m =&gt; m.SettingValue) %&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type="submit" value="Save" class="uiButton" /&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td colspan="3"&gt;
              &lt;%=Html.ValidationMessageFor(m=&gt;m.SettingValue) %&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;%= Html.HiddenFor(m =&gt; m.SettingName)%&gt;
  &lt;%= Html.HiddenFor(m =&gt; m.Name)%&gt;
  
  &lt;%} %&gt;
  </code></pre>
  
  <p>GlobalSettingsController.cs</p>
  
  <pre><code>public ActionResult Index()
          {
              var settings = GetSettings();
  
              if (TempData["Message"] != null)
              {
                  settings.Message = TempData["Message"].ToString();
                  settings.HasMessage = true;
              }
  
              return View(settings);
          }
  
          [AuthorizationFilter(true, null)]
          [HttpPost]
          public ActionResult Save(GlobalSettingsViewModel model)
          {
              if (ModelState.IsValid)
              {
                  GlobalSettings.SetGlobalSetting(model.Settings[0].SettingName, model.Settings[0].SettingValue);
                  TempData["Message"] = "Saved " + model.Settings[0].Name;
                  return RedirectToAction("Index");
              }
  
              var settings = GetSettings();
  
              return View("Index", settings);            
      }
  </code></pre>