Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 234
Ian Vink Avatar asked Feb 27 '13 23:02

Ian Vink


2 Answers

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;
}
like image 181
Daniel Imms Avatar answered Nov 19 '22 19:11

Daniel Imms


Simply surrounding it with a div should do the trick

<div>@Html.ValidationMessageFor(m => m.Email)</div> 
like image 6
simple-thomas Avatar answered Nov 19 '22 18:11

simple-thomas