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

Kendo UI ASP.NET MVC Kendo Grid Edit Popup Globalization Validation Issue

3 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 21 Oct 2014, 07:12 PM
i have a Kendo grid that uses an edit Popup. The culture in the client is de-DE, when an user tries to edit a decimal number i.e. 8,5 Kendo sends a null to the server for that value and returns validation message "The value 8.5 is not valid for 'PropertyName'". Any help will be greatly appreciated.

@{
var culture = System.Globalization.CultureInfo.CurrentCulture.ToString();
}

<script src="@Url.Content("~/Scripts/Kendo/cultures/kendo.culture." + culture + ".min.js")"></script>

<script type="text/javascript">
kendo.culture("@culture");
</script>

jQuery.extend(jQuery.validator.methods, {
date: function (value, element) {
return this.optional(element) || kendo.parseDate(value) != null;
},
number: function (value, element) {
return this.optional(element) || kendo.parseFloat(value) != null;
}
});
@(Html.Kendo().Grid<SalesToolkit.ViewModels.AdminEquipDimViewModel.Equipment>()
.Name("grdEquipDim")
.Columns(columns =>
{
columns.Bound(dim => dim.EquipmentID).Width(50).Title("ID").Hidden(true);
columns.Bound(dim => dim.EquipmentName).Width(140).Title("Equipment Name");
columns.ForeignKey(dim => dim.EquipmentTypeID, (System.Collections.IEnumerable)ViewData["EquipTypes"], "EquipmentTypeID", "EquipmentName").Width(60).Title("Type");

columns.Bound(dim => dim.Metric).Width(55);
columns.Bound(dim => dim.ModelVerified).Width(65);
columns.Bound(dim => dim.LastModifiedBy).Width(130);
columns.Bound(dim => dim.TimeStamp).Format("{0:MM/dd/yyyy hh:mm:ss}").Width(120);

columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Scrollable()
.HtmlAttributes(new { @class = "dimGrid" })
.Sortable()
.Pageable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Field(dim => dim.EquipmentID).Editable(false);
model.Field(dim => dim.TimeStamp).Editable(false);
model.Field(dim => dim.LastModifiedBy).Editable(false);
})
.Events(events => events.Error("error"))
.Model(model => model.Id(dim => dim.EquipmentID))
.Create(update => update.Action("EquipDim_Create", "AdminEquipDim", new { mID = Model.ManufacturerID }))
.Read(read => read.Action("EquipDim_Read", "AdminEquipDim", new { mID = Model.ManufacturerID }))
.Update(update => update.Action("EquipDim_Update", "AdminEquipDim"))
.Destroy(update => update.Action("EquipDim_Delete", "AdminEquipDim"))
)
)

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EquipDim_Update([DataSourceRequest] DataSourceRequest request, AdminEquipDimViewModel.Equipment equipMfg)
{
if (equipMfg != null && ModelState.IsValid)
{
AdminEquipDim oEquipMfg = new AdminEquipDim();
oEquipMfg.UpdateEquipDim(equipMfg);
}

return Json(ModelState.ToDataSourceResult());
}



3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 23 Oct 2014, 03:46 PM
Hello John,

I assume that the issue that you have is because the server culture is not changed accordingly. Please notice that you need to dynamically change both cultures and keep them in sync so the same format should be used to transfer numbers.

I strongly suggest you to check our implementation in the MVC demos that we provide once you install the MVC extensions.

For reference here is part of the controller from the example (Grid - Globalization demo):

using System.Globalization;
using System.Threading;
using System.Web.Mvc;
using Kendo.Mvc.Examples.Models;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
 
namespace Kendo.Mvc.Examples.Controllers
{
    public partial class GridController
    {
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            if (!string.IsNullOrEmpty(requestContext.HttpContext.Request["culture"]))
            {
                Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo(requestContext.HttpContext.Request["culture"]);
            }
            base.Initialize(requestContext);
        }
 
        public ActionResult Globalization()
        {
            return View(productService.Read());
        }
 
        public ActionResult Globalization_Read([DataSourceRequest] DataSourceRequest request)
        {
            return Json(productService.Read().ToDataSourceResult(request));
        }
 
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Globalization_Create([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
        {
            if (product != null && ModelState.IsValid)
            {
                productService.Create(product);
            }
 
            return Json(new[] { product }.ToDataSourceResult(request, ModelState));
        }
 
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Globalization_Update([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
        {
            if (product != null && ModelState.IsValid)
            {
                productService.Update(product);
            }
 
            return Json(ModelState.ToDataSourceResult());
        }
 
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Globalization_Destroy([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
        {
            if (product != null)
            {
                productService.Destroy(product);
            }
 
            return Json(ModelState.ToDataSourceResult());
        }
    }
}

The above code changes the culture of the thread accordingly to the culture parameter before the ModelBinder kicks in.

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
John
Top achievements
Rank 1
answered on 28 Oct 2014, 02:17 AM
Thanks for following up,

I could not find the demos you are referring. From the “Available
Downloads for DevCraft Complete” section I downloaded “Extensions for ASP.NET
MVC (discontinued)” and “Kendo UI Professional”

I checked the server culture and it is the same as in the
client. I think the problem is that the grid edit popup automatically changes the
inputs to the US culture i.e. 8,5 to 8.5 before sending to the server.

Kendo Numeric Textboxes post fine to the server.

 

 

 
0
Petur Subev
Telerik team
answered on 29 Oct 2014, 02:31 PM
Hello John,

The MVC demos should be inside the "UI for ASP.NET MVC". You will see in the demo the format under which they are send to the server is different (for DE culture it uses comas and for US culture it uses dots).

http://www.telerik.com/aspnet-mvc

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
John
Top achievements
Rank 1
Share this question
or