0
/api/WebService?param1=1&price=6.2 working
/api/WebService?param1=1&price=6,2 not working. The request is invalid error.

サーバーの地域設定は、カンマに応じて設定し、私はまだそれがコンマでは動作しないのWebConfigにグローバル化「TR-TR」を置きます。私はModelBinderを試しただけでなく、どちらも動作しません。取り扱い小数点パラメータ

どのようにカンマで動作させることができますか?

+0

。小数点を使用している可能性があります –

+0

はい、これは解決策の1つですが、残念ながら残念です。 –

答えて

0

このような使用のモデルバインダー:

で発見
public class DecimalModelBinder : IModelBinder 
{ 
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) 
    { 
    ValueProviderResult valueResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); 
    ModelState modelState = new ModelState { Value = valueResult }; 
    object actualValue = null; 
    try 
    { 
     actualValue = Convert.ToDecimal(valueResult.AttemptedValue, CultureInfo.CurrentCulture); 
    } 
    catch (FormatException e) 
    { 
     modelState.Errors.Add(e); 
    } 

    bindingContext.ModelState.Add(bindingContext.ModelName, modelState); 
    return actualValue; 
    } 
} 


protected void Application_Start() 
{ 
    AreaRegistration.RegisterAllAreas(); 
    RegisterGlobalFilters(GlobalFilters.Filters); 
    RegisterRoutes(RouteTable.Routes); 

    //HERE you tell the framework how to handle decimal values 
    ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder()); 

    DependencyResolver.SetResolver(new ETAutofacDependencyResolver()); 
} 

:あなたは、文字列型として価格パラメータを確認する必要がありASP.NET MVC datetime culture issue when passing value back to controller

関連する問題