1

I am developing MVC application with Kedno grid. I have a model Item with properties:

public bool IsPaid { get; set; }
public Nullable<DateTime> PaymentDate { get; set; }

In Kedno grid in the View:

columns.Bound(c => c.PaymentDate).Format("{0:dd-MMM-yyyy}");

When I am editing in the grid and set IsPaid to false to logic has to be setting PaymentDate to null.

For example I have an Item with PaymentDate 22-Sep-2016 and IsPaid to true.

After editing in Kendo grid this Item setting IsPaid to false, and when I click Save Changes, it is invoked the method Update in the controller:

public ActionResult Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ItemViewModel> items)
{
        if (ModelState.IsValid)
        {
            //
        }
}

But the ModelState is not valid: "The value '9/22/2016 12:00:00 AM' is not valid for...". If the PaymentDate is 01-Sep-2016, the ModelState is valid.

Also, I followed the steps in the Globalization section.

In web.config:

<globalization uiCulture="bg-BG" culture="bg-BG"></globalization>

In Controller:

protected override void Initialize(RequestContext requestContext)
{
    Thread.CurrentThread.CurrentCulture =
        Thread.CurrentThread.CurrentUICulture =
            new CultureInfo(requestContext.HttpContext.Request.UserLanguages[0]);

    base.Initialize(requestContext);
}

In View:

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

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

<script>
    kendo.culture("@culture");
</script>

Any suggestions?

Thanks a lot!

randominstanceOfLivingThing
  • 16,873
  • 13
  • 49
  • 72

1 Answers1

0

The issue is not related to matching cultures on the Server and on the Client. As to my observations, you have correctly followed the article.

The reason why the model view is invalid is that you have set the Format method of the Column to a format that is like "dd-MMM-yyyy". Try setting the format as:

columns.Bound(c => c.PaymentDate).Format("{0:dd/mm/yyyy}");

Alternatively, you can remove the formatting for testing purposes and check if the date is going to be passed correctly. You can put it back later on.

Ceco Milchev
  • 377
  • 3
  • 11