This is a migrated thread and some comments may be shown as answers.

NumericTextBoxFor returning null value when decimal

3 Answers 905 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
UBALDI SI
Top achievements
Rank 1
UBALDI SI asked on 12 Feb 2019, 10:42 AM

 

I use a gridview with inline editing, when i Update a double value with 

This is the grid :

@(Html.Kendo().Grid<Ubaldi.BoB2B.Web.Models.FraisDePort.FraisDePortViewModel>()
         .Name("FraisGrid")
         .Columns(columns =>
         {
             columns.Bound(e => e.Id).Hidden(true);
             columns.Bound(e => e.Article);
             columns.Bound(e => e.PoidsMin).ClientTemplate("#= PoidsMin # kg");
             columns.Bound(e => e.PoidsMax).ClientTemplate("#= PoidsMax # kg");
             columns.Bound(e => e.MontantHT).ClientTemplate("#= MontantHT # €");
             columns.Command(command => { command.Edit().UpdateText("Enregistrer").CancelText("Annuler").Text(" ");}).Width(100);
             columns.Command(command =>
             {
                 command.Custom("Logs").Click("FraisLogs")
                     .Text("<span class='fa fa-list-alt'></span>")
                     .HtmlAttributes(new { @class = "btn btn-info", title = "Voir les modifications effectuées sur l'Article de Transport" });
             }).Width(50);
         })
         .Editable(editable => editable.Mode(GridEditMode.InLine))
         .DataSource(dataSource => dataSource
             .Ajax()
             .Events(events => events.Error("error_handler"))
             .Read(read => read.Action("GetAll", "FraisDePort"))
             .Update(update => update.Action("Update", "FraisDePort").Data("addUser"))
             .Model(model =>
             {
                 model.Id(p => p.Id);
             })
             .PageSize(20)
         )
         .Pageable(pageable => pageable.ButtonCount(5)))

 

This is my View Model:

public class FraisDePortViewModel : IValidatableObject
   {
 
       public int Id { get; set; }
 
       [Required, StringLength(100, MinimumLength = 3, ErrorMessage = "Le Nom de l'Article de Transport doit faire entre 3 et 100 charactères")]
       [DisplayName("Article de Transport")]
       public string Article { get; set; }
 
       [Required]
       [UIHint("Poids")]
       public double? PoidsMin { get; set; }
 
       [Required]
       [UIHint("Poids")]
       public double? PoidsMax { get; set; }
 
       [UIHint("Currency")]
       [Required, Range(1, 9999, ErrorMessage = "Le Montant HT doit être supérieur à 0 €")]
       public decimal? MontantHT { get; set; }
 
       [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy HH:mm}", ApplyFormatInEditMode = true)]
       [DisplayName("Créé le")]
       public DateTime? DateCreation { get; set; }
 
       [DisplayName("Créé par")]
       public string UserCreation { get; set; }
 
       [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy HH:mm}", ApplyFormatInEditMode = true)]
       [DisplayName("Modifié le")]
       public DateTime? DateModification { get; set; }
 
       [DisplayName("Modifié par")]
       public string UserModification { get; set; }
 
       public List<FraisDePortLog> Modifications { get; set; }
 
       public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
       {
           if (PoidsMin > PoidsMax)
           {
               yield return new ValidationResult("Le Poids Minimum doit être supérieur au Poids Maximum ", new List<string> { "Poids" });
           }
       }
   }

 

This is my EditorTemplate "Poids"

@model double?
 
@(Html.Kendo().NumericTextBoxFor(m => m)
      .Culture("fr-FR")
      .Min(0)
      .Max(15)
      .Step(0.50))
      

 

This is what i receive when I post modification with decimals (see Attachement).

Additionnals info :

  • Kendo 2018.3.911.545 
  • Culture is set to fr-FR in web.config solution

Do you have an idea to fix this issue of null value ?

Thank you, 

Julien

 

3 Answers, 1 is accepted

Sort by
0
UBALDI SI
Top achievements
Rank 1
answered on 12 Feb 2019, 11:58 AM
I use a gridview with inline editing, when i Update a double value with decimal, the value in the model returned null in the update action method *
0
Tsvetomir
Telerik team
answered on 14 Feb 2019, 09:06 AM
Hello,

I have investigated the provided code snippets and I have noticed that Editor template uses a French culture. Whereas, the decimal separator of the French culture is a comma

When the cultures on the client and on the server do not match unexpected behavior might occur. More specifically, the number is sent from the client with comma separator while the server tries to parse it as a dot. When the parser returns an error, a null value is assigned to the model field.

In order to unify the cultures on the client and on the server, follow the instructions in the following article:

https://docs.telerik.com/aspnet-mvc/getting-started/globalization#match-cultures

Let me know in case the issue persists after implementing the above suggestion.


Kind regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
UBALDI SI
Top achievements
Rank 1
answered on 15 Feb 2019, 09:17 AM

Hello Tsvetomir,

It works as expected ! 

Thank you for your help.

Julien

Tags
NumericTextBox
Asked by
UBALDI SI
Top achievements
Rank 1
Answers by
UBALDI SI
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or