pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

      <bdo id='fJ9eG'></bdo><ul id='fJ9eG'></ul>
    1. <legend id='fJ9eG'><style id='fJ9eG'><dir id='fJ9eG'><q id='fJ9eG'></q></dir></style></legend>
      <i id='fJ9eG'><tr id='fJ9eG'><dt id='fJ9eG'><q id='fJ9eG'><span id='fJ9eG'><b id='fJ9eG'><form id='fJ9eG'><ins id='fJ9eG'></ins><ul id='fJ9eG'></ul><sub id='fJ9eG'></sub></form><legend id='fJ9eG'></legend><bdo id='fJ9eG'><pre id='fJ9eG'><center id='fJ9eG'></center></pre></bdo></b><th id='fJ9eG'></th></span></q></dt></tr></i><div class="rltvrbv" id='fJ9eG'><tfoot id='fJ9eG'></tfoot><dl id='fJ9eG'><fieldset id='fJ9eG'></fieldset></dl></div>

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

      <tfoot id='fJ9eG'></tfoot>

    2. TagHelpers 基于驗證屬性為 LabelTagHelper 添加自定義

      TagHelpers add custom class for LabelTagHelper based on validation attribute [Required](TagHelpers 基于驗證屬性為 LabelTagHelper 添加自定義類 [必需])

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

      • <tfoot id='tcmRE'></tfoot>
        • <bdo id='tcmRE'></bdo><ul id='tcmRE'></ul>
            <tbody id='tcmRE'></tbody>
          1. <i id='tcmRE'><tr id='tcmRE'><dt id='tcmRE'><q id='tcmRE'><span id='tcmRE'><b id='tcmRE'><form id='tcmRE'><ins id='tcmRE'></ins><ul id='tcmRE'></ul><sub id='tcmRE'></sub></form><legend id='tcmRE'></legend><bdo id='tcmRE'><pre id='tcmRE'><center id='tcmRE'></center></pre></bdo></b><th id='tcmRE'></th></span></q></dt></tr></i><div class="55j7tdl" id='tcmRE'><tfoot id='tcmRE'></tfoot><dl id='tcmRE'><fieldset id='tcmRE'></fieldset></dl></div>

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

              1. 本文介紹了TagHelpers 基于驗證屬性為 LabelTagHelper 添加自定義類 [必需]的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                在 Core MVC 中,有一個新概念,即標簽助手.

                In Core MVC there is anew concept as Tag helpers.

                我們之前可以創建自定義 html 幫助器,以根據驗證數據注釋附加一些類,例如 [Required].

                We could previously create custom html helpers to attach some classes based on the validation data annotations such as [Required].

                作為 TagHelpers arq 相當新的領域,我找不到足夠的資源來實現以下目標:

                As TagHelpers arq quite new area I cannot find anough resources to achieve the following:

                這是視圖模型:

                    [Required]
                    public Gender Gender { get; set; }
                

                查看:

                <label class="control-label col-md-3 required" asp-for="Gender"></label>
                

                css:

                .required:after {
                content: "*";
                font-weight: bold;
                color: red;
                }
                

                輸出:

                但我不想在標簽中手動添加所需的 css 類.不知何故,我應該能夠擴展 LabelTagHelper 以讀取模型數據注釋,如果它具有 [Required] 然后在標簽元素中添加所需的類.

                But I don't want to manully add the required css class in the label. Somehow I shoudl be able to extend the LabelTagHelper to read model data annotations and if it has the [Required] then add required class in the label element.

                謝謝,

                推薦答案

                是的,您可以通過從 LabelTagHelper 類繼承并首先將您自己的類添加到屬性列表中來輕松擴展它.

                Yup, you can extend this pretty easily by inheriting from the LabelTagHelper class and adding in your own class to the attribute list first.

                [HtmlTargetElement("label", Attributes = "asp-for")]
                public class RequiredLabelTagHelper : LabelTagHelper
                {
                    public RequiredLabelTagHelper(IHtmlGenerator generator) : base(generator)
                    {
                    }
                
                    public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
                    {
                        if (For.Metadata.IsRequired)
                        {
                            CreateOrMergeAttribute("class", "required", output);
                        }
                
                        return base.ProcessAsync(context, output);
                    }
                
                    private void CreateOrMergeAttribute(string name, object content, TagHelperOutput output)
                    {
                        var currentAttribute = output.Attributes.FirstOrDefault(attribute => attribute.Name == name);
                        if (currentAttribute == null)
                        {
                            var attribute = new TagHelperAttribute(name, content);
                            output.Attributes.Add(attribute);
                        }
                        else
                        {
                            var newAttribute = new TagHelperAttribute(
                                name,
                                $"{currentAttribute.Value.ToString()} {content.ToString()}",
                                currentAttribute.ValueStyle);
                            output.Attributes.Remove(currentAttribute);
                            output.Attributes.Add(newAttribute);
                        }
                    }
                }
                

                這篇關于TagHelpers 基于驗證屬性為 LabelTagHelper 添加自定義類 [必需]的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標記群集圖標顏色,繼承其余默認 CSS 屬性)
                How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認加載磁貼顏色?)
                How do I show a label beyond a certain zoom level in Leaflet?(如何在 Leaflet 中顯示超出特定縮放級別的標簽?)
                Assign ID to marker in leaflet(為傳單中的標記分配 ID)
                react-leaflet map not correctly displayed(反應傳單地圖未正確顯示)
                Set Leaflet Overlay Off in the Layer Control(在圖層控件中設置 Leaflet Overlay Off)

                  <tfoot id='msByf'></tfoot>
                  <i id='msByf'><tr id='msByf'><dt id='msByf'><q id='msByf'><span id='msByf'><b id='msByf'><form id='msByf'><ins id='msByf'></ins><ul id='msByf'></ul><sub id='msByf'></sub></form><legend id='msByf'></legend><bdo id='msByf'><pre id='msByf'><center id='msByf'></center></pre></bdo></b><th id='msByf'></th></span></q></dt></tr></i><div class="5rn5v5l" id='msByf'><tfoot id='msByf'></tfoot><dl id='msByf'><fieldset id='msByf'></fieldset></dl></div>
                    <tbody id='msByf'></tbody>
                    <bdo id='msByf'></bdo><ul id='msByf'></ul>

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

                    • <legend id='msByf'><style id='msByf'><dir id='msByf'><q id='msByf'></q></dir></style></legend>

                          主站蜘蛛池模板: 土壤养分检测仪_肥料养分检测仪_土壤水分检测仪-山东莱恩德仪器 大型多片锯,圆木多片锯,方木多片锯,板材多片锯-祥富机械有限公司 | 3d可视化建模_三维展示_产品3d互动数字营销_三维动画制作_3D虚拟商城 【商迪3D】三维展示服务商 广东健伦体育发展有限公司-体育工程配套及销售运动器材的体育用品服务商 | 5nd音乐网|最新流行歌曲|MP3歌曲免费下载|好听的歌|音乐下载 免费听mp3音乐 | POM塑料_PBT材料「进口」聚甲醛POM杜邦原料、加纤PBT塑料报价格找利隆塑料 | 路斯特伺服驱动器维修,伦茨伺服驱动器维修|万骏自动化百科 | 管理会计网-PCMA初级管理会计,中级管理会计考试网站 | 医用空气消毒机-医用管路消毒机-工作服消毒柜-成都三康王 | 影合社-影视人的内容合作平台 | 水质传感器_水质监测站_雨量监测站_水文监测站-山东水境传感科技有限公司 | 气动隔膜阀_气动隔膜阀厂家_卫生级隔膜阀价格_浙江浙控阀门有限公司 | 刺绳_刀片刺网_刺丝滚笼_不锈钢刺绳生产厂家_安平县浩荣金属丝网制品有限公司-安平县浩荣金属丝网制品有限公司 | 土壤墒情监测站_土壤墒情监测仪_土壤墒情监测系统_管式土壤墒情站-山东风途物联网 | 闪电优家-卫生间防水补漏_酒店漏水渗水维修_防水堵漏公司 | 阳光模拟试验箱_高低温试验箱_高低温冲击试验箱_快速温变试验箱|东莞市赛思检测设备有限公司 | 粉末冶金-粉末冶金齿轮-粉末冶金零件厂家-东莞市正朗精密金属零件有限公司 | 北京软件开发_软件开发公司_北京软件公司-北京宜天信达软件开发公司 | 深圳离婚律师咨询「在线免费」华荣深圳婚姻律师事务所专办离婚纠纷案件 | 氮化镓芯片-碳化硅二极管 - 华燊泰半导体 | 防爆电机生产厂家,YBK3电动机,YBX3系列防爆电机,YBX4节防爆电机--河南省南洋防爆电机有限公司 | 全自动包装秤_全自动上袋机_全自动套袋机_高位码垛机_全自动包装码垛系统生产线-三维汉界机器(山东)股份有限公司 | 3A别墅漆/3A环保漆_广东美涂士建材股份有限公司【官网】 | 超声波气象站_防爆气象站_空气质量监测站_负氧离子检测仪-风途物联网 | 领先的大模型技术与应用公司-中关村科金 | 神超官网_焊接圆锯片_高速钢锯片_硬质合金锯片_浙江神超锯业制造有限公司 | 建筑资质代办-建筑资质转让找上海国信启航 | 膜片万向弹性联轴器-冲压铸造模具「沧州昌运模具」 | 浙江美尔凯特智能厨卫股份有限公司| 无锡市珂妮日用化妆品有限公司|珂妮日化官网|洗手液厂家 | 橡胶接头|可曲挠橡胶接头|橡胶软接头安装使用教程-上海松夏官方网站 | 防弹玻璃厂家_防爆炸玻璃_电磁屏蔽玻璃-四川大硅特玻科技有限公司 | 南京泽朗生物科技有限公司 | 贝朗斯动力商城(BRCPOWER.COM) - 买叉车蓄电池上贝朗斯商城,价格更超值,品质有保障! | 内窥镜-工业内窥镜厂家【上海修远仪器仪表有限公司】 | 焊接减速机箱体,减速机箱体加工-淄博博山泽坤机械厂 | 江苏大隆凯科技有限公司 | 膜结构车棚|上海膜结构车棚|上海车棚厂家|上海膜结构公司 | 六维力传感器_三维力传感器_二维力传感器-南京神源生智能科技有限公司 | 东莞压铸厂_精密压铸_锌合金压铸_铝合金压铸_压铸件加工_东莞祥宇金属制品 | 硬度计_影像测量仪_维氏硬度计_佛山市精测计量仪器设备有限公司厂家 | 磁棒电感生产厂家-电感器厂家-电感定制-贴片功率电感供应商-棒形电感生产厂家-苏州谷景电子有限公司 | 外观设计_设备外观设计_外观设计公司_产品外观设计_机械设备外观设计_东莞工业设计公司-意品深蓝 |