Search code examples
razormvcrazor

MVC Razor field label gets overlapped when copy and paste


<div class="labelled-text-field">
     @Html.LabelFor(x => x.Email)
     @Html.TextBoxFor(x => x.Email)
     @Html.ValidationMessageFor(x => x.Email)
</div>

enter image description here

When using right click -> paste label gets overlapped with the pasted email:

enter image description here

When typing or using Ctrl+v (paste) work well:

enter image description here

I dont know if using a razor oncopy event is the way to fix this:

@Html.TextBoxFor(x => x.Email, 
              new { 
                    @class = "input_box", 
                    id = "txtDays", 
                    onpaste="" 
                  }
               ) 

Solution

  • Try the placeholder attribute. It will clear the watermark when you paste the text.

    <div class="labelled-text-field">
        @Html.LabelFor(x => x.Email)
        @Html.TextBoxFor(x => x.Email, new {placeholder="Your Email" })
        @Html.ValidationMessageFor(x => x.Email)
    </div>