<bdo id='oojPh'></bdo><ul id='oojPh'></ul>
    1. <i id='oojPh'><tr id='oojPh'><dt id='oojPh'><q id='oojPh'><span id='oojPh'><b id='oojPh'><form id='oojPh'><ins id='oojPh'></ins><ul id='oojPh'></ul><sub id='oojPh'></sub></form><legend id='oojPh'></legend><bdo id='oojPh'><pre id='oojPh'><center id='oojPh'></center></pre></bdo></b><th id='oojPh'></th></span></q></dt></tr></i><div id='oojPh'><tfoot id='oojPh'></tfoot><dl id='oojPh'><fieldset id='oojPh'></fieldset></dl></div>
      <tfoot id='oojPh'></tfoot>

    2. <legend id='oojPh'><style id='oojPh'><dir id='oojPh'><q id='oojPh'></q></dir></style></legend>

      <small id='oojPh'></small><noframes id='oojPh'>

        如何自定义 text-danger 给出的验证错误消息?

        How to customize validation error message given by text-danger?(如何自定义 text-danger 给出的验证错误消息?)
          <tbody id='Pj8JE'></tbody>

            <bdo id='Pj8JE'></bdo><ul id='Pj8JE'></ul>
          • <i id='Pj8JE'><tr id='Pj8JE'><dt id='Pj8JE'><q id='Pj8JE'><span id='Pj8JE'><b id='Pj8JE'><form id='Pj8JE'><ins id='Pj8JE'></ins><ul id='Pj8JE'></ul><sub id='Pj8JE'></sub></form><legend id='Pj8JE'></legend><bdo id='Pj8JE'><pre id='Pj8JE'><center id='Pj8JE'></center></pre></bdo></b><th id='Pj8JE'></th></span></q></dt></tr></i><div id='Pj8JE'><tfoot id='Pj8JE'></tfoot><dl id='Pj8JE'><fieldset id='Pj8JE'></fieldset></dl></div>

                <small id='Pj8JE'></small><noframes id='Pj8JE'>

                <legend id='Pj8JE'><style id='Pj8JE'><dir id='Pj8JE'><q id='Pj8JE'></q></dir></style></legend>

                  <tfoot id='Pj8JE'></tfoot>
                1. 本文介绍了如何自定义 text-danger 给出的验证错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的 MVC .NET Core 项目的一个页面上有一个下拉列表,我想为其自定义默认验证文本.

                  I have a dropdown list on one of my pages in my MVC .NET Core project that I want to customise the default validation text for.

                  <select asp-for="ProductID" class="form-control" asp-items="ViewBag.ProductID">
                      <option value="">--Select Product --</option>
                  </select>
                  <span asp-validation-for="ProductID" class="text-danger" />
                  

                  给出的标准验证错误消息是产品 ID 字段是必需的".我想把它改成别的东西.

                  The standard validation error message given is "The Product ID field is required". I want to change this to something else.

                  我试过用这个

                   <span asp-validation-for="ProductID" class="text-danger">Please enter a product</span>
                  

                  但是当页面加载而不是单击按钮时会显示错误消息

                  But the error message displays when the page loads instead of when the button is clicked

                  自定义验证文本的适当方法是什么?

                  What is the appropriate way to customise validation text?

                  推荐答案

                  一般是在你想要返回Controller的ViewModel中完成:

                  That's normally done in the ViewModel you want to return to the Controller:

                  public class SomeViewModel
                  {
                      [Required(ErrorMessage = "Your elegant error message goes here")]
                      public int ProductId { get; set; }
                  }
                  

                  这篇关于如何自定义 text-danger 给出的验证错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                    <bdo id='XnDg8'></bdo><ul id='XnDg8'></ul>

                      <legend id='XnDg8'><style id='XnDg8'><dir id='XnDg8'><q id='XnDg8'></q></dir></style></legend>
                        <tbody id='XnDg8'></tbody>

                        • <i id='XnDg8'><tr id='XnDg8'><dt id='XnDg8'><q id='XnDg8'><span id='XnDg8'><b id='XnDg8'><form id='XnDg8'><ins id='XnDg8'></ins><ul id='XnDg8'></ul><sub id='XnDg8'></sub></form><legend id='XnDg8'></legend><bdo id='XnDg8'><pre id='XnDg8'><center id='XnDg8'></center></pre></bdo></b><th id='XnDg8'></th></span></q></dt></tr></i><div id='XnDg8'><tfoot id='XnDg8'></tfoot><dl id='XnDg8'><fieldset id='XnDg8'></fieldset></dl></div>
                          <tfoot id='XnDg8'></tfoot>

                          <small id='XnDg8'></small><noframes id='XnDg8'>