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

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

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

        <tfoot id='FMb8w'></tfoot>

        帶有自定義 ResourceProvider 的 DataAnnotation

        DataAnnotation with custom ResourceProvider(帶有自定義 ResourceProvider 的 DataAnnotation)
          <tbody id='g5jEN'></tbody>

      1. <tfoot id='g5jEN'></tfoot>

          <bdo id='g5jEN'></bdo><ul id='g5jEN'></ul>

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

                  本文介紹了帶有自定義 ResourceProvider 的 DataAnnotation的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我創建了一個自定義ResourceProvider來從數據庫中提取本地化信息.我現在想使用 DataAnnotation 為模型添加驗證.

                  I have created a custom ResourceProvider to pull localization information from a database. I now want to use DataAnnotation to add validation to the model.

                  DataAnnotation 具有 ErrorMessageResourceTypeErrorMessageResourceName 屬性,但 ErrorMessageResourceType 只接受 System.Type(即編譯好的資源文件)

                  DataAnnotation has ErrorMessageResourceType and ErrorMessageResourceName properties but ErrorMessageResourceType only accepts System.Type (i.e. a compiled resource file)

                  有沒有辦法讓 DataAnnotation 使用自定義的 ResourceProvider?

                  Is there any way to get DataAnnotation to use the custom ResourceProvider?

                  推薦答案

                  我意識到這是一個老問題,但想補充一點.我發現自己處于同樣的情況,似乎沒有關于這個主題的任何文檔/博客.盡管如此,我還是想出了一種使用自定義資源提供程序的方法,但需要注意的是.需要注意的是,我在一個 MVC 應用程序中,所以我仍然有 HttpContext.GetLocalResourceObject() 可用.這是 asp.net 用來本地化項目的方法.資源對象的缺失不會阻止您編寫我們自己的解決方案,即使它是直接查詢數據庫表.不過,我認為值得指出.

                  I realize this is an old question, but wanted to add a bit. I found myself in the same situation and there doesn't appear to be any documentation/blogumentation on this topic. Nevertheless, I figured out a way to use a custom resource provider, with one caveat. The caveat is that I'm in an MVC application so I still have HttpContext.GetLocalResourceObject() available. This is the method that asp.net uses to localize items. The absence of the resource object doesn't stop you from writing our own solution, even if its a direct query of the DB tables. Nevertheless, I thought it was worth pointing out.

                  雖然我對以下解決方案不太滿意,但它似乎有效.對于我想使用的每個驗證屬性,我都從所述屬性繼承并重載 IsValid().裝修是這樣的:

                  While I'm not terribly happy with the following solution, it seems to work. For each validation attribute I want to use I inherit from said attribute and overload the IsValid(). The decoration looks like this:

                  [RequiredLocalized(ErrorMessageResourceType= typeof(ClassBeginValidated), ErrorMessageResourceName="Errors.GenderRequired")]
                  public string FirstName { get; set; } 
                  

                  新屬性如下所示:

                  public sealed class RequiredLocalized : RequiredAttribute {
                  
                      public override bool IsValid(object value) {
                  
                          if ( ! (ErrorMessageResourceType == null || String.IsNullOrWhiteSpace(ErrorMessageResourceName) )   ) {
                              this.ErrorMessage = MVC_HtmlHelpers.Localize(this.ErrorMessageResourceType, this.ErrorMessageResourceName);
                              this.ErrorMessageResourceType = null;
                              this.ErrorMessageResourceName = null;
                          }
                          return base.IsValid(value);
                      }
                  }
                  

                  注意事項

                  • 您需要使用派生屬性而不是標準屬性來裝飾您的代碼
                  • 我正在使用 ErrorMessageResourceType 來傳遞正在驗證的類的類型.我的意思是,如果我在客戶類中并驗證 FirstName 屬性,我將通過 typeof(customer).我這樣做是因為在我的數據庫后端中,我使用完整的類名(命名空間 + 類名)作為鍵(與在 asp.net 中使用頁面 URL 的方式相同).
                    • MVC_HtmlHelpers.Localize 只是我的自定義資源提供程序的一個簡單包裝器
                    • You need to decorate your code with the derived attribute, not the standard one
                    • I'm using ErrorMessageResourceType to pass the type of the class being validated. By that I mean if I'm in a customer class and validating the FirstName property I would pass typeof(customer). I'm doing this because in my database backend I'm using the full class name (namespace + classname) as a key (the same way a page URL is used in asp.net).
                      • MVC_HtmlHelpers.Localize is just a simple wrapper for my custom resource provider

                      (半被盜的)幫助代碼看起來像這樣......

                      The (semi-stolen) helper code looks like this ....

                      public static string Localize (System.Type theType, string resourceKey) {
                          return Localize (theType, resourceKey, null);
                      }
                      public static string Localize (System.Type theType, string resourceKey, params object[] args) {
                          string resource = (HttpContext.GetLocalResourceObject(theType.FullName, resourceKey) ?? string.Empty).ToString();
                          return mergeTokens(resource, args);
                      }
                      
                      private static string mergeTokens(string resource, object[] args)        {
                          if (resource != null && args != null && args.Length > 0) {
                              return string.Format(resource, args);
                          }  else {
                              return resource;
                          }
                      }
                      

                      這篇關于帶有自定義 ResourceProvider 的 DataAnnotation的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標簽的 XML)
                  Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                  delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                  Parse malformed XML(解析格式錯誤的 XML)

                          <tfoot id='2x5HA'></tfoot>

                          <small id='2x5HA'></small><noframes id='2x5HA'>

                            <tbody id='2x5HA'></tbody>

                          <i id='2x5HA'><tr id='2x5HA'><dt id='2x5HA'><q id='2x5HA'><span id='2x5HA'><b id='2x5HA'><form id='2x5HA'><ins id='2x5HA'></ins><ul id='2x5HA'></ul><sub id='2x5HA'></sub></form><legend id='2x5HA'></legend><bdo id='2x5HA'><pre id='2x5HA'><center id='2x5HA'></center></pre></bdo></b><th id='2x5HA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2x5HA'><tfoot id='2x5HA'></tfoot><dl id='2x5HA'><fieldset id='2x5HA'></fieldset></dl></div>

                            <bdo id='2x5HA'></bdo><ul id='2x5HA'></ul>

                          • <legend id='2x5HA'><style id='2x5HA'><dir id='2x5HA'><q id='2x5HA'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 二区三区视频 | 亚洲日本欧美日韩高观看 | 亚洲美女天堂网 | 国产高清一区二区 | 黄色网址在线播放 | 国产一区二区电影 | 中文字幕一区二区三区四区五区 | a亚洲精品 | 亚洲一区久久 | 这里只有精品999 | 国产探花在线精品一区二区 | 999久久| 在线中文字幕亚洲 | 91精品久久久久久久久 | 日韩午夜 | 性国产丰满麻豆videosex | 成人国产精品入口免费视频 | 欧美一级久久精品 | 亚洲风情在线观看 | 欧美日韩在线观看视频网站 | julia中文字幕久久一区二区 | 日韩视频在线免费观看 | 九九免费 | 成人在线中文字幕 | 国产一区三区在线 | 超碰520| 精品一区二区三区四区 | 中文在线观看视频 | 久久精品国产一区二区三区不卡 | 国产欧美在线一区 | 97色在线观看免费视频 | 国产91在线 | 中日 | 成人福利网站 | 美日韩精品 | 高清成人免费视频 | 精品亚洲永久免费精品 | 91国内精品久久 | 你懂的国产 | 亚洲一二三在线观看 | 久久精品国产亚洲夜色av网站 | 91久操视频 |