1

I have the following behaviour in my program:

User input for a decimal variable

A) jquery validation turned off:
1) If the user uses a comma as decimal separator, the value is stored correctly in the ViewModel
2) If the user uses a point as decimal separator, the value is multiplied by 100 (as if there was no decimal separator)

B) jquery validation turned on:
1) I get an error, that a number must be supplied
2) same Problem as A2)

However if I display a decimal value of the ViewModel in the view it is shown per default with a point as a decimal separator.
This inconsistency is confusing me and I would like to implement a consistent behaviour, but unfortunately I don't know what I am actually looking for.

The website will be localized in german and italian. The localization works without any problems, so far. This is my

startup.cs

namespace XXX
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Added - uses IOptions<T> for your settings.
            services.AddOptions();

            // Added - Confirms that we have a home for our DemoSettings
            services.Configure<DatabaseSettings>(Configuration.GetSection("DatabaseSettings"));


            services.AddLocalization(options => options.ResourcesPath = "Resources");
            services.AddAuthentication(IISDefaults.AuthenticationScheme);
            services.AddMvc()
                .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
                .AddDataAnnotationsLocalization();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseStatusCodePagesWithReExecute("/Error/Index", "?i_statusCode={0}");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }



            app.UseStaticFiles();

            IList<CultureInfo> supportedCultures = new List<CultureInfo>
            {
                    new CultureInfo("de"),
                    new CultureInfo("it"),
            };


            var localizationOptions = new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("de"),
                SupportedCultures = supportedCultures,
                SupportedUICultures = supportedCultures
            };



            var requestProvider = new RouteDataRequestCultureProvider();
            localizationOptions.RequestCultureProviders.Insert(0, requestProvider);

            app.UseRouter(routes =>
            {
                routes.MapMiddlewareRoute("{culture=de}/{*mvcRoute}", subApp =>
                {
                    subApp.UseRequestLocalization(localizationOptions);

                    subApp.UseMvc(mvcRoutes =>
                    {
                        mvcRoutes.MapRoute(
                            name: "defaultLocalized",
                            template: "{culture=de}/{controller=Contract}/{action=Index}/{id?}");

                        mvcRoutes.MapRoute(
                          name: "error",
                          template: "Error/Index",
                          defaults: new { controller = "Error", action = "Index", culture = "de" });

                        mvcRoutes.MapRoute(
                          name: "default",
                          template: "{*catchall}",
                          defaults: new { controller = "Home", action = "Index", culture = "de" });
                    });
                });
            });
        }
    }
}
misanthrop
  • 771
  • 7
  • 32
  • You need to reconfigure the validator if you want to use the comma as the decimal separator - refer [MVC/JQuery validation does not accept comma as decimal separator](https://stackoverflow.com/questions/48066208/mvc-jquery-validation-does-not-accept-comma-as-decimal-separator/48247324#48247324) –  Jul 09 '18 at 10:53
  • Ok thanks but this does not solve my problem that values are displayed with a point as default, does it? – misanthrop Jul 09 '18 at 10:56
  • The link addresses the _I get an error, that a number must be supplied_. error –  Jul 09 '18 at 10:58
  • ok thanks for this part... I would however like to solve this issue in a second step because I think it is more important that the value is loaded in the view correctly (with a comma instead of a point) – misanthrop Jul 09 '18 at 13:13

0 Answers0