title: MVC RC Validation: Is this right?
body: <p>I'm just trying to do some simple validation in MVC RC and am getting an error.  For the purposes of this question, I am <strong>not using the UpdateModel</strong>.</p>
  
  <p>Here is the code in the form:</p>
  
  <pre><code>&lt;%= Html.TextBox("UserId")%&gt;
  &lt;%= Html.ValidationMessage("UserId") %&gt;
  </code></pre>
  
  <p>If I add the following line in the controller, I will get a NullReferenceException on the TextBox:</p>
  
  <pre><code>ModelState.AddModelError("UserId", "*");
  </code></pre>
  
  <p>So to fix this, I've also added the following line:</p>
  
  <pre><code>ModelState.SetModelValue("UserId", ValueProvider["UserId"]);
  </code></pre>
  
  <p>Why am I having to rebind the value?  <strong>I only have to do this if I add the error</strong>, but it seems like I shouldn't have to do this.  I feel like Im doing something incorrectly or just not familiar enough with binding.</p>
  
  <p>It looks like Im not the only one who has seen this.  Per request, here is the controller code:</p>
  
  <pre><code>[AcceptVerbs(HttpVerbs.Post)]
      public ActionResult Create(FormCollection collection)
      {
          AppUser newUser = new AppUser();
  
          try
          {
              newUser.UserId = collection["UserId"];
  
              AppUserDAL.AddUser(newUser);
  
              return RedirectToAction("Index");
          }
          catch (Exception ex)
          {
              ViewData["ReturnMessage"] = ex.Message;
  
              ModelState.AddModelError("UserId", "*");
              ModelState.SetModelValue("UserId", ValueProvider["UserId"]);
  
  
              return View(newUser);
          }
  </code></pre>