久久久久久久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>

                          主站蜘蛛池模板: 波多野结衣中文字幕一区二区三区 | 国产免费色 | 亚洲精品久久久久久国产精华液 | 亚洲视频一区二区三区 | 欧美性生活一区二区三区 | 中文字幕在线一区二区三区 | 国产精品免费观看 | 亚洲第一在线视频 | 国产精品美女久久久久久久网站 | 天天看天天爽 | 久草资源网站 | av在线天堂网 | 国产精品高清一区二区三区 | 亚洲免费在线 | 成人久久| 一本一道久久a久久精品综合蜜臀 | 97人澡人人添人人爽欧美 | 99热这里只有精品8 激情毛片 | 欧美黄色一级毛片 | 亚洲欧美综合精品另类天天更新 | 免费成人国产 | 亚洲免费在线播放 | 亚洲精品1 | 欧美自拍第一页 | 日韩视频1 | 亚洲3级| 久久久久久国产精品 | 久久99国产精一区二区三区 | 久草精品在线 | 欧美一区在线视频 | 三级在线视频 | 国产精品不卡视频 | 天天视频一区二区三区 | 91香蕉嫩草 | 91精品一区二区三区久久久久久 | 久久国产精品-国产精品 | 国产精品一区一区 | 久久一区精品 | 国产一级视频在线 | 亚洲精品91 | 久久久久免费精品国产小说色大师 |