How can I ensure Kendo Grid passes a numeric value with the correct separator to ASP.NET MVC?

338 Views Asked by At

I have a simple grid that uses a custom popup editor template. In the template, I'd like to use a Numeric Textbox.

Due to localization, the application keeps trying to use a comma to separate decimals in the numeric values. When these values are passed to the ASP.NET MVC back-end, the value is lost and null is passed. How can I ensure the posted value has a period separator?

I have tried setting the underlying field values to 2.5 instead of 2,5 in the grid's Save event, as well as tried to overwrite the e.model.WeightKg to 2.5. The value is still passed with a comma separator, as shown by inspecting the form data in the request.

My grid:

@(Html.Kendo().Grid<PackageViewModel>()
    .Name("PackageGrid")
    .Columns(columns => {
        columns.Bound(o => o.PackageCode);
        columns.Bound(o => o.WeightKg);
        columns.Command(o => o.Edit());
    })
    .DataSource(d => d
        .WebApi()
        .Model(m => m.Id(o => o.PackageCode))
        .Read(c => c.Url(Url.HttpRouteUrl("DefaultApi", new { controller = "Packages" })))
        .Create(c => c.Url(Url.HttpRouteUrl("DefaultApi", new { controller = "Packages" })))
        .Destroy(c => c.Url(Url.HttpRouteUrl("DefaultApi", new { controller = "Packages" id = "{0}" })))
        .Update(c => c.Url(Url.HttpRouteUrl("DefaultApi", new { controller = "Packages" id = "{0}" })))
        .PageSize(20)
    )
    .Editable(e => e.Mode(GridEditMode.PopUp).TemplateName("Package"))
    .Selectable()
    .Deferred()
)

The numeric textbox in the template:

@Html.Kendo().NumericTextBoxFor(m => m.WeightKg).Decimals(8)

And finally, the unparsed form data, followed by the parsed form data:

sort=&group=&filter=&PackageCode=DOOS-B&WeightKg=2%2C5

sort:
group:
filter:
PackageCode:DOOS-B
WeightKg:2,5
0

There are 0 best solutions below