Ian Vink
Ian Vink

Reputation: 68800

ASP.NET MVC3: ValidationMessageFor on new line

I have a validation message for my model:

    <td colspan="2">
        <div class="rereg-input">
           @Html.TranslatedTextBoxFor(m => m.Email)
           @Html.ValidationMessageFor(m => m.Email)
         </div>
     </td>

When the user forgets, the text nicely displays a * beside the field:

enter image description here

But when they enter a bad email, the message gets put on the end. How can I get it under?

enter image description here

Upvotes: 7

Views: 6256

Answers (2)

Daniel Imms
Daniel Imms

Reputation: 50229

You need to rearrange/fix the CSS/HTML structure.

<td colspan="2">
    <div class="rereg-input">
        @Html.TranslatedTextBoxFor(m => m.Email)
        <div>
            @Html.ValidationMessageFor(m => m.Email)
        </div>
    </div>
</td>

You may be better off modifying whatever CSS class MVC puts on the validation message element and set display:block;.

.validation-message {
    /* ... */
    display:block;
}

Upvotes: 8

simple-thomas
simple-thomas

Reputation: 729

Simply surrounding it with a div should do the trick

<div>@Html.ValidationMessageFor(m => m.Email)</div> 

Upvotes: 6

Related Questions