ASP.NET MVC - Determine if field has an error in Razor view
<p>I'm working on an input form in ASP.NET MVC. My input form looks like this:</p>

<pre><code>@using (Html.BeginForm("Result", "Contact", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { role="form" }))
{
  &lt;h4&gt;What do you want to tell us?&lt;/h4&gt;
  @Html.ValidationSummary(true, "", new { @class = "text-danger" })

  &lt;div class="form-group label-floating"&gt;
    &lt;label class="control-label" for="Subject"&gt;Subject&lt;/label&gt;
    &lt;input class="form-control" id="Subject" name="Subject" type="text"&gt;
  &lt;/div&gt;

  &lt;div class="form-group"&gt;
    &lt;input type="submit" value="Send" class="btn btn-primary btn-raised" /&gt;
  &lt;/div&gt;

  @Html.AntiForgeryToken()
}
</code></pre>

<p>My model behind this form looks like this:</p>

<pre><code>public class ContactModel
{
  [Required(ErrorMessage="Please enter the subject.")]
  [Display(Name="Subject")]
  public string Subject { get; set; }
}
</code></pre>

<p>I want to conditionally apply classes and structure based on whether or not the Model is valid. I also want to do it per field. My question is, in Razor, how do determine if the "Subject" property is valid, or if it has errors? Thanks!</p>