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

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

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

    2. <legend id='YTwxC'><style id='YTwxC'><dir id='YTwxC'><q id='YTwxC'></q></dir></style></legend>
        <bdo id='YTwxC'></bdo><ul id='YTwxC'></ul>

        Aspnet Core 十進制綁定不適用于非英語文化

        Aspnet Core Decimal binding not working on non English Culture(Aspnet Core 十進制綁定不適用于非英語文化)
          <tbody id='3UKYM'></tbody>

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

            • <tfoot id='3UKYM'></tfoot>

                1. 本文介紹了Aspnet Core 十進制綁定不適用于非英語文化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個使用非英語配置(西班牙語)運行的 aspnet 核心應用程序:

                  I have an aspnet core app that runs with a non english configuration (spanish):

                  public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
                      {
                          ......
                          app.UseRequestLocalization(new RequestLocalizationOptions
                          {
                              DefaultRequestCulture = new RequestCulture(new CultureInfo("es-AR"))
                              ,SupportedCultures = new List<CultureInfo>
                              {
                                  new CultureInfo("es-AR")
                              }
                              ,SupportedUICultures = new List<CultureInfo>
                              {
                                  new CultureInfo("es")
                              }
                          });
                  
                          .........
                      }
                  

                  在英語中,十進制數的小數部分用點分隔,但在西班牙語中使用逗號:

                  In english a decimal number has its decimal part delimited with a dot, but in spanish a comma is used:

                  • 10256.35 英文
                  • 10256,35 西班牙語

                  我在控制器中有這個動作:

                  I have this action in a controller:

                   [HttpPost]
                   public decimal Test(decimal val)
                   {
                       return val;
                   }
                  

                  如果我使用郵遞員并向該操作發送一個像 {val: 15.30} 這樣的 json,那么操作中的 val 會收到 0(由于文化,綁定不起作用).如果我發送這樣的 json {val: 15,30} 然后在操作中我收到 15.30我遇到的問題是,我需要接受帶逗號的小數的操作,因為這是來自應用程序表單中輸入類型文本的格式.但我還需要接受帶有來自 json 格式請求的點的小數.無法在接受逗號的 json 中指定小數/浮點數(不能將其作為字符串發送).我怎樣才能做到這一點???我快把自己逼瘋了.

                  If I use postman and send to that action a json like this {val: 15.30}, then val in the action recives a 0 (binding not working because of the culture). If I send a json like this {val: 15,30} then in the action I recive 15.30 The problem I have is, I need the action to accept decimals with commas, because that is the format that comes from inputs type text in the app's forms. But i also need to accept decimal with a dot that comes from request in json format. There is no way to specify a decimal/float in json that accepts a comma (send it as string is not an option). How can I do this??? I'm driving my self crazy with this.

                  謝謝!!

                  推薦答案

                  顯然,ASP.NET core 1.0.0 中的十進制綁定默認不是文化不變的.模型綁定取決于服務器文化.

                  Apparently, the decimal binding in ASP.NET core 1.0.0 is not culture invariant by default. The model binding depends on the server culture.

                  您可以按照 Stephen Muecke 的建議使用自定義模型綁定來更改此行為.這是我的基于 自定義模型綁定在 ASP.Net核心 1.0 (RTM)

                  You can change this behavior with a custom model binding as suggested by Stephen Muecke. Here is mine based on Custom Model Binding in ASP.Net Core 1.0 (RTM)

                  public class InvariantDecimalModelBinderProvider : IModelBinderProvider
                  {
                      public IModelBinder GetBinder(ModelBinderProviderContext context)
                      {
                          if (context == null) throw new ArgumentNullException(nameof(context));
                  
                          if (!context.Metadata.IsComplexType && (context.Metadata.ModelType == typeof(decimal) || context.Metadata.ModelType == typeof(decimal?)))
                          {
                              return new InvariantDecimalModelBinder(context.Metadata.ModelType);
                          }
                  
                          return null;
                      }
                  }
                  
                  public class InvariantDecimalModelBinder : IModelBinder
                  {
                      private readonly SimpleTypeModelBinder _baseBinder;
                  
                      public InvariantDecimalModelBinder(Type modelType)
                      {
                          _baseBinder = new SimpleTypeModelBinder(modelType);
                      }
                  
                      public Task BindModelAsync(ModelBindingContext bindingContext)
                      {
                          if (bindingContext == null) throw new ArgumentNullException(nameof(bindingContext));
                  
                          var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
                  
                          if (valueProviderResult != ValueProviderResult.None)
                          {
                              bindingContext.ModelState.SetModelValue(bindingContext.ModelName, valueProviderResult);
                  
                              var valueAsString = valueProviderResult.FirstValue;
                              decimal result;
                  
                              // Use invariant culture
                              if (decimal.TryParse(valueAsString, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out result))
                              {
                                  bindingContext.Result = ModelBindingResult.Success(result);
                                  return Task.CompletedTask;
                              }
                          }
                  
                          // If we haven't handled it, then we'll let the base SimpleTypeModelBinder handle it
                          return _baseBinder.BindModelAsync(bindingContext);
                      }
                  }
                  

                  在 Startup.cs 中:

                  And in Startup.cs:

                  services.AddMvc(config =>
                  {
                      config.ModelBinderProviders.Insert(0, new InvariantDecimalModelBinderProvider());
                  });
                  

                  這篇關于Aspnet Core 十進制綁定不適用于非英語文化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='0yFBH'></tfoot>
                        <tbody id='0yFBH'></tbody>
                      <legend id='0yFBH'><style id='0yFBH'><dir id='0yFBH'><q id='0yFBH'></q></dir></style></legend>
                    • <i id='0yFBH'><tr id='0yFBH'><dt id='0yFBH'><q id='0yFBH'><span id='0yFBH'><b id='0yFBH'><form id='0yFBH'><ins id='0yFBH'></ins><ul id='0yFBH'></ul><sub id='0yFBH'></sub></form><legend id='0yFBH'></legend><bdo id='0yFBH'><pre id='0yFBH'><center id='0yFBH'></center></pre></bdo></b><th id='0yFBH'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0yFBH'><tfoot id='0yFBH'></tfoot><dl id='0yFBH'><fieldset id='0yFBH'></fieldset></dl></div>

                      <small id='0yFBH'></small><noframes id='0yFBH'>

                        • <bdo id='0yFBH'></bdo><ul id='0yFBH'></ul>

                            主站蜘蛛池模板: 夜夜操天天干 | 国产精品性做久久久久久 | 亚洲男人的天堂网站 | 日韩中文字幕区 | 精品国产高清一区二区三区 | 蜜桃视频一区二区三区 | 亚洲日本视频 | 国产成人精品一区 | 在线播放中文 | 国产成人99久久亚洲综合精品 | 一本大道久久a久久精二百 国产成人免费在线 | 亚洲国产精品一区二区久久 | 在线观看欧美日韩视频 | 一区二区三区中文字幕 | 欧美夜夜 | h在线看 | 四虎成人免费视频 | 国产一级片91 | 成人欧美一区二区三区在线播放 | 日本在线视频一区二区 | 91视频在线观看免费 | 天天影视网天天综合色在线播放 | 高清免费av | 亚洲精品久久视频 | 91av精品 | 99久久久99久久国产片鸭王 | 全免费a级毛片免费看视频免费下 | 成人精品一区亚洲午夜久久久 | 日本高清aⅴ毛片免费 | 国产日韩欧美激情 | 欧美二三区 | 欧美日韩在线免费观看 | 日本午夜免费福利视频 | 日一区二区三区 | 午夜精品一区二区三区在线视频 | 日本天堂视频在线观看 | 99久久99久久精品国产片果冰 | 一级黄色毛片a | 国产乱码精品一区二区三区中文 | 日韩中文一区二区 | 综合久久av|