locked
highlight textbox on validation error asp.net core RRS feed

  • Question

  • User2041008840 posted

    In ASP.net Core 
    I set the validation in model 

    [Required]
    public string Name {get;set;}

    but in view 
    it show like this 

    After submit - 
    Shows error *Required field (error message) 
    span element show in red color but textbox does not highlighted in red color.

    How do i make textbox border red color if there is error

    <div class="form-group">
                   <label asp-for="Name" class="control-label"></label>
                   <input asp-for="Name" class="form-control" />
                   <span asp-validation-for="Name" class="text-danger"></span>
               </div>
    Thursday, October 17, 2019 5:37 AM

Answers

  • User61956409 posted

    Hi Prathamesh,

    Prathamesh Shende

    After submit - 
    Shows error *Required field (error message) 
    span element show in red color but textbox does not highlighted in red color.

    How do i make textbox border red color if there is error

    To achieve the requirement, you can apply custom CSS styles to input(s) that have validation error, like below.

    <style>
        input.input-validation-error{
            border-color:red;
        }
    </style>

    Test Result

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 17, 2019 6:48 AM