久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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>

                          主站蜘蛛池模板: 中文字幕视频在线观看免费 | 一级黄色片日本 | 精品久久久久久亚洲国产800 | 青青草华人在线视频 | 久久精品日 | 欧美8一10sex性hd | 日韩精品1区2区3区 爱爱综合网 | 午夜激情在线 | 中文字幕国产 | 久久精品视频在线免费观看 | 日本在线你懂的 | 九九热热九九 | 久久久久久久一区二区三区 | 一级网站 | 久久一区二区免费视频 | 日韩精品免费 | 日本不卡一区二区三区在线观看 | 美女一区二区在线观看 | 亚洲精品视频网站在线观看 | 青青草综合 | 精产嫩模国品一二三区 | 亚洲欧美日韩精品久久亚洲区 | 国产免费自拍 | 亚洲一区二区在线视频 | 精品久久久久久久久久久久久 | 成人国产精品一级毛片视频毛片 | 亚州激情 | 国产精品一区二区视频 | 久久夜色精品国产 | 欧美在线网站 | 国产一区二区三区免费 | 色网站视频 | 色综合久久久 | 亚洲一区二区三区四区五区中文 | 国产乱码精品一品二品 | 在线免费观看成人 | 最新91在线 | 国产羞羞视频在线观看 | 国产在线中文字幕 | 男女羞羞视频在线免费观看 | 五月激情婷婷在线 |