Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82251

Date formatting is strange in editor

$
0
0

I have two datatable editors. Both need to return dates in Dutch format, edit etc.

This is the C# code for one table:

[HttpGet]
        [HttpPost]
        public ActionResult LeningenTable([FromForm]string GebouwID = "-1")
        {

            using (var db = new Database("azure", _configuration.GetConnectionString("BBGroepDataContext")))
            {
                var editor = new Editor(db, "Leningen", "Id")
                    .Model<LeningViewModel>()
                    .Field(new Field("Leningverstrekker")
                        .Validator(Validation.NotEmpty(new ValidationOpts { Message = "De naam van de leningverstrekker is verplicht." }))
                     )
                    .Field(new Field("StartDatum")
                        .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Voer een geldige datum in." }))
                        .GetFormatter(Format.DateSqlToFormat("dd/MM/yyyy"))
                        .SetFormatter(Format.DateFormatToSql("dd/MM/yyyy"))
                     )
                    .Field(new Field("EindDatum")
                        .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Voer een geldige datum in." }))
                        .GetFormatter(Format.DateSqlToFormat("dd/MM/yyyy"))
                        .SetFormatter(Format.DateFormatToSql("dd/MM/yyyy"))
                     )
                    .Field(new Field("Hoofdsom")
                       .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Voer een getal in." }))
                        .Validator(Validation.Numeric("nl-NL", new ValidationOpts { Message = "Voer een getal in." }))
                     )
                    .Field(new Field("Aflossingspercentage")
                         .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Voer een getal in tussen de 0 en 100." }))
                        .Validator(Validation.MinMaxNum(0, 100, new ValidationOpts { Message = "Voer een getal in tussen de 0 en 100." }))
                     )
                    .Field(new Field("Voorwaarden")
                        .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Voer een getal in." }))
                     )
                    .Field(new Field("GebouwId")
                        .SetValue(GebouwID)
                     )
                    .Where("gebouwId", GebouwID);

                editor.PostCreate += (sender, e) => _LogChange(db, "Leningen", "create", e.Id, e.Values);
                editor.PostEdit += (sender, e) => _LogChange(db, "Leningen", "edit", e.Id, e.Values);
                editor.PostRemove += (sender, e) => _LogChange(db, "Leningen", "remove", e.Id, e.Values);

                var response = editor.Process(Request).Data();

                return Json(response);
            }
        }

When I look at the response I see this for the dates:

StartDatum: {6-6-2020 00:00:00}

However. The datatable in the client view shows: 2020-06-06T00:00:00

I also have this code in the same controller:

```
[HttpGet]
[HttpPost]
public ActionResult HuurdersTable([FromForm]string GebouwID = "-1")
{

        using (var db = new Database("azure", _configuration.GetConnectionString("BBGroepDataContext")))
        {
            var editor = new Editor(db, "Huurders", "id")
                .Model<HuurderViewModel>("Huurders")
                .Field(new Field("NaamHuurder")
                    .Validator(Validation.NotEmpty(new ValidationOpts { Message = "De naam van de huurder is verplicht." }))
                 )
                .Field(new Field("Huisnummer")
                    .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Het huisnummer is verplicht." }))
                 )
                .Field(new Field("HuurcontractHuurder")
                    .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Het Huurcontract is verplicht." }))
                 )
                .Field(new Field("StartDatumContract")
                    .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Voer een geldige datum in." }))
                    .GetFormatter(Format.DateSqlToFormat("dd/MM/yyyy"))
                    .SetFormatter(Format.DateFormatToSql("dd/MM/yyyy"))
                 )
                .Field(new Field("EindDatumContract")
                    .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Voer een geldige datum in." }))
                    .GetFormatter(Format.DateSqlToFormat("dd/MM/yyyy"))
                    .SetFormatter(Format.DateFormatToSql("dd/MM/yyyy"))
                 )
                .Field(new Field("Opzegtermijn")
                   .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Voer een getal in." }))
                    .Validator(Validation.Numeric("nl-NL", new ValidationOpts { Message = "Voer een getail in." }))
                 )
                .Field(new Field("AantalM2VVO")
                     .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Voer een getal in." }))
                    .Validator(Validation.Numeric("nl-NL", new ValidationOpts { Message = "Voer een getail in." }))
                 )
                .Field(new Field("AantalM2BVO")
                     .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Voer een getal in." }))
                    .Validator(Validation.Numeric("nl-NL", new ValidationOpts { Message = "Voer een getail in." }))
                 )
                .Field(new Field("GebouwId")
                    .SetValue(GebouwID)
                 )
                .Where("GebouwId", GebouwID)
                .MJoin(new MJoin("HuurderExtraEigenschappen")
                    .Link("Huurders.id", "HuurderExtraEigenschappen.HuurderId")
                    .Field(new Field("id"))
                )
                ;

            editor.PostCreate += (sender, e) => _LogChange(db, "Huurders", "create", e.Id, e.Values);
            editor.PostEdit += (sender, e) => _LogChange(db, "Huurders", "edit", e.Id, e.Values);
            editor.PostRemove += (sender, e) => _LogChange(db, "Huurders", "remove", e.Id, e.Values);

            var response = editor.Process(Request).Data();

            return Json(response);
        }
    }

```
For this code the response shows: StartDatumContract: "02-06-2020"

And on the client side everything is fine.

Please help.


Viewing all articles
Browse latest Browse all 82251

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>