Replacing div if there is any validation error connected with the div value I have an input group:

&lt;div class="input-group"&gt;
    &lt;div class="input-group-addon"&gt;
        @Html.DisplayNameFor(m =&gt; m.StorageId)
    &lt;/div&gt;
    @if(ViewData.ModelState["StorageError"] !=null &amp;&amp; ViewData.ModelState["StorageError"].Errors.Count&gt;0)
    {
        &lt;div class="a" title="@ViewData.ModelState["StorageError"].Errors[0].ErrorMessage" data-toggle="tooltip" data-placement="left" id="storage"&gt;
            @Html.DropDownList("storageId", null, new { @class = "form-control",@style="border-color:red" })
        &lt;/div&gt;
    }
    else
    {
        &lt;div class="a" title="@String.Empty" data-toggle="tooltip" data-placement="left" id="storage"&gt;
            @Html.DropDownList("storageId", null, new { @class = "form-control" })
        &lt;/div&gt;
    }
&lt;/div&gt;


As you can see, if there are no errors, the site should render div without a red border and tooltip.

Do you think it's efficient and good-looking enough to leave it as it is, or does it need to be rewritten?
Basically, 95% of your code is the same between the two sections, so I'd prefer to use just a single instance with a bool on the page.

@{ 
    var error = ViewModel.ModelState["StorateError"];
    var hasErrors = error != null &amp;&amp; error.Errors.Any();
}

&lt;div class="a" title="@( hasErrors ? error.Errors[0].ErrorMessage : string.Empty" )
    data-toggle="tooltip" data-placement="left" id="storage"&gt;
        @Html.DropDownList("storageId", null, new { @class="form-control",
            @style=" @( hasErrors ? "border-color:red", string.Empty ) })
&lt;/div&gt;


You should also get into the habit of using .Any() instead of Count() &gt; 0 as Any will stop iterating after it finds the first item that matches the filtering (usually not a big deal, but the collection could get rather large, and it's a minor change to coding that could give big performance enhancements).

The only other thing I might recommend would be to have a CSS class for border-color:red instead of inline styling.