title: How can I add errors to ModelState using the correct key in ASP.NET MVC?
body: <p>I want to perform some simple form validation in my controller. </p>
  
  <p>Here's an excerpt from the controller action:</p>
  
  <pre><code>// other code
  
              if (!string.IsNullOrEmpty(editModel.NewPassword)
                  &amp;&amp; editModel.RepeatNewPassword != editModel.NewPassword)                {
                  // problem line... How to I get the key from editModel?
                  ModelState.AddModelError("", "The new password does not match the repeated password.")
              }
  
  // other code
  </code></pre>
  
  <p>It appears that must use a string as the error's key. Is there a way i can generate the corect key from the model, or should I just check for what input name <code>Html.PasswordFor(x =&gt; x.NewPassword)</code> returns?</p>