久久久久久久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 十進(jìn)制綁定不適用于非英語(yǔ)文化

        Aspnet Core Decimal binding not working on non English Culture(Aspnet Core 十進(jìn)制綁定不適用于非英語(yǔ)文化)
          <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 十進(jìn)制綁定不適用于非英語(yǔ)文化的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我有一個(gè)使用非英語(yǔ)配置(西班牙語(yǔ))運(yùn)行的 aspnet 核心應(yīng)用程序:

                  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")
                              }
                          });
                  
                          .........
                      }
                  

                  在英語(yǔ)中,十進(jìn)制數(shù)的小數(shù)部分用點(diǎn)分隔,但在西班牙語(yǔ)中使用逗號(hào):

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

                  • 10256.35 英文
                  • 10256,35 西班牙語(yǔ)

                  我在控制器中有這個(gè)動(dòng)作:

                  I have this action in a controller:

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

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

                  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 中的十進(jìn)制綁定默認(rèn)不是文化不變的.模型綁定取決于服務(wù)器文化.

                  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 的建議使用自定義模型綁定來(lái)更改此行為.這是我的基于 自定義模型綁定在 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());
                  });
                  

                  這篇關(guān)于Aspnet Core 十進(jìn)制綁定不適用于非英語(yǔ)文化的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

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

                            主站蜘蛛池模板: 在线观看中文字幕一区二区 | 久草网址 | 国产在线视频一区二区 | 无码国模国产在线观看 | 中文字幕一区二区三区在线观看 | 国产高清久久 | 国产在线色 | 成人午夜激情 | 国产农村一级国产农村 | 国产一区二区自拍 | 91精品国模一区二区三区 | 九九视频在线观看视频6 | 在线免费看毛片 | 久久www免费视频 | 亚洲a在线视频 | 国产一区二区三区在线 | 日本高清不卡视频 | 成人免费在线视频 | 日韩三级电影一区二区 | 91精品国产乱码久久久久久 | 先锋资源网站 | 欧美日韩国产一区二区三区 | 欧美在线视频网站 | 日韩第一区 | 久久久久久九九九九九九 | 九九九久久国产免费 | 亚洲精品第一页 | 国产成人精品一区二区三区四区 | 久久久123| 一级片网址 | 欧美色综合一区二区三区 | 欧美一区二区在线 | 午夜视频导航 | 中文字幕一区二区三区四区五区 | 男人天堂午夜 | 男女视频在线免费观看 | 国内激情av片| 精品无码久久久久久国产 | 久久国 | a级免费观看视频 | 国产精品色 |