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>

                          主站蜘蛛池模板: 智能型高压核相仪-自动开口闪点测试仪-QJ41A电雷管测试仪|上海妙定 | 广州中央空调回收,二手中央空调回收,旧空调回收,制冷设备回收,冷气机组回收公司-广州益夫制冷设备回收公司 | BOE画框屏-触摸一体机-触控查询一体机-触摸屏一体机价格-厂家直销-触发电子 | 加中寰球移民官网-美国移民公司,移民机构,移民中介,移民咨询,投资移民 | 空气能暖气片,暖气片厂家,山东暖气片,临沂暖气片-临沂永超暖通设备有限公司 | 代理记账_公司起名核名_公司注册_工商注册-睿婕实业有限公司 | 磁力加热搅拌器-多工位|大功率|数显恒温磁力搅拌器-司乐仪器官网 | 耐酸碱胶管_耐腐蚀软管总成_化学品输送软管_漯河利通液压科技耐油耐磨喷砂软管|耐腐蚀化学软管 | 窖井盖锯圆机_锯圆机金刚石锯片-无锡茂达金刚石有限公司 | 陕西安闸机-伸缩门-车牌识别-广告道闸——捷申达门业科技 | 中视电广_短视频拍摄_短视频推广_短视频代运营_宣传片拍摄_影视广告制作_中视电广 | 中视电广_短视频拍摄_短视频推广_短视频代运营_宣传片拍摄_影视广告制作_中视电广 | 辽宁资质代办_辽宁建筑资质办理_辽宁建筑资质延期升级_辽宁中杭资质代办 | 风淋室生产厂家报价_传递窗|送风口|臭氧机|FFU-山东盛之源净化设备 | 中式装修设计_全屋定制家具_实木仿古门窗花格厂家-喜迎门 | 江苏农村商业银行招聘网_2024江苏农商行考试指南_江苏农商行校园招聘 | 并网柜,汇流箱,电控设备,中高低压开关柜,电气电力成套设备,PLC控制设备订制厂家,江苏昌伟业新能源科技有限公司 | 金环宇|金环宇电线|金环宇电缆|金环宇电线电缆|深圳市金环宇电线电缆有限公司|金环宇电缆集团 | sus630/303cu不锈钢棒,440C/430F/17-4ph不锈钢研磨棒-江苏德镍金属科技有限公司 | 无菌水质袋-NASCO食品无菌袋-Whirl-Pak无菌采样袋-深圳市慧普德贸易有限公司 | 砍排机-锯骨机-冻肉切丁机-熟肉切片机-预制菜生产线一站式服务厂商 - 广州市祥九瑞盈机械设备有限公司 | 智能终端_RTU_dcm_北斗星空自动化科技 | 岩棉切条机厂家_玻璃棉裁条机_水泥基保温板设备-廊坊鹏恒机械 | 济南宣传册设计-画册设计_济南莫都品牌设计公司 | 海南在线 海南一家 | 上海瑶恒实业有限公司|消防泵泵|离心泵|官网 | 欧景装饰设计工程有限公司-无锡欧景装饰官网 | 样品瓶(色谱样品瓶)百科-浙江哈迈科技有限公司 | 代办建筑资质升级-建筑资质延期就找上海国信启航 | 北京乾茂兴业科技发展有限公司 | 脱硝喷枪-氨水喷枪-尿素喷枪-河北思凯淋环保科技有限公司 | 服务器之家 - 专注于服务器技术及软件下载分享 | 不锈钢列管式冷凝器,换热器厂家-无锡飞尔诺环境工程有限公司 | 光伏家 - 太阳能光伏发电_分布式光伏发电_太阳能光伏网 | 广东恩亿梯电源有限公司【官网】_UPS不间断电源|EPS应急电源|模块化机房|电动汽车充电桩_UPS电源厂家(恩亿梯UPS电源,UPS不间断电源,不间断电源UPS) | 成都亚克力制品,PVC板,双色板雕刻加工,亚克力门牌,亚克力标牌,水晶字雕刻制作-零贰捌广告 | 消电检公司,消电检价格,北京消电检报告-北京设施检测公司-亿杰(北京)消防工程有限公司 | 一技任务网_有一技之长,就来技术任务网 | 深圳宣传片制作_产品视频制作_深圳3D动画制作公司_深圳短视频拍摄-深圳市西典映画传媒有限公司 | 西门子伺服控制器维修-伺服驱动放大器-828D数控机床维修-上海涌迪 | 南京租车,南京汽车租赁,南京包车,南京会议租车-南京七熹租车 |