How to remove validation-info in text?

mc 3,641 Reputation points
2023-01-27T12:33:03.2066667+00:00

in Index.cshtml

  <form>
        <div class="row">
            <div class="col-sm-2">
                <label class="col-form-label">客户:</label>
                <div>
                    <input type="text" class="form-control" placeholder="客户名称、手机号" asp-for="Name" />
</div>
</div>
</div>
</form>

in Index.cshtml.cs

public string Name{get;set;}

when I open the page the text of Name is with class :'.input-validation-error' but I do not need it it can be null.

how to remove it?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,156 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,252 questions
{count} votes

Accepted answer
  1. Zhi Lv - MSFT 32,011 Reputation points Microsoft Vendor
    2023-01-30T03:28:17.1333333+00:00

    Hi @打玻璃

    when I open the page the text of Name is with class :'.input-validation-error' but I do not need it it can be null.

    First, I checked your code on my Razor page application, there doesn't have the '.input-validation-error' class. Perhaps it is relating your client-side validation package, you can check it.

    On my side, the result as below:

    User's image

    Second, if you don't validate the Name and let it nullable, you can change the code as below:

    public string? Name{get;set;}
    

    After that, the rendered html elements as below:

    User's image


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Dillion

    0 comments No comments

0 additional answers

Sort by: Most helpful