Home>

Good evening. Tell me how to bring the date of the DD-MM-YY format to the standard DateTime, exposing the time of the middle of the day. Now in the model I have incorrect format consisting of only the date received by the picker, and the DateTime gets up in {1/1/0001 12:00:00 am}. The situation is even more interesting. Here is a view, where the picker works fine:

@using (Ajax.beginform ("Addtask", "Task", New AjaxOptions
{
    Httpmethod= "post",
    INSERTIONMODE= INSERTIONMODE.REPLACE,
    UpdateTargetID= "CONTENT"
}))
{
            ≪
INPUT ID= "DATEPICKER" NAME= "ENDDATE" TYPE= "TEXT" CLASS= "FORM-CONTROL" DATA-VAL= "TRUE" DATA-VAL-REQUIRED= "You must select the end date of the task" Data-Val-Date= " Enter the correct date ">
            ≪
Span class= "Field-Validation-Valid" Data-Valmsg-for= "EndDate" Data-Valmsg-Replace= "True" >
≪
/span >
            ≪
Button class= "BTN BTN-PRIMARY BTN-BLOCK" TYPE= "Submit" >
Add <
/Button >
}

This is a partial view, so in the parent here:

$ ('Body'). ON ('Click', '#DatePicker', Function (Event) {
            $ (this) .datepicker ({
                Changemonth: True,
                ChangeYear: True,
                DateFormat: "MM /DD /YY",
                Mindate: +1,
                MaxDate: '+ 2y',
            });
            $ (this) .focus (). Get (0);
    });

Action:

[httppost]
    Public Virtual ActionResult Addtask (AddtaskModel Model)
    {
        if (modelstate.isvalid)
        {
            model.add ();
            Return PartialView ("Success");
        }
        RETURN VIEW (NEW AddTaskModel ());
    }

And here it is already returning a default. View:

@using ("Edit", "Task", new ajaxoptions
{
    Httpmethod= "post",
    INSERTIONMODE= INSERTIONMODE.REPLACE,
    UpdateTargetID= "CONTENT"
}))
{
    .Validationsummary (True)
    ≪
H3 >
Task end date: @ model.endtime.toshortdatestring () <
/h3 >
    ≪
INPUT ID= "DATEPICKER" NAME= "ENDDATE" TYPE= "TEXT" CLASS= "FORM-CONTROL" DATA-VAL= "TRUE" DATA-VAL-REQUIRED= "You must select the end date of the task" Data-Val-Date= " Enter the correct date ">
    ≪
Span class= "Field-Validation-Valid" Data-Valmsg-for= "EndDate" Data-Valmsg-Replace= "True" >
≪
/span >
    ≪
Button class= "BTN BTN-PRIMARY BTN-BLOCK" TYPE= "Submit" >
Change <
/Button >
}
So I understand the problem in the fact that I first used the model of the model to show and immediately change it to the dietpiker?

@mikemilansky about what language is we talking about?

DreamChild2021-04-24 10:37:16

c# and I have 2 views -on creating an object, there the date is clinging normally, and here to edit where I change only the date in the model, but it is exposed by default.

mikemilansky2021-04-24 10:37:16

@mikemilansky Show the code, you would not want to guess on the coffee grounds. Namely marking with a datapicker, code coding from the client to the server (form or Ajax) and the action on the server that processes the data obtained

DreamChild2021-04-24 10:37:16

Wash the standard "glitch" is most likely expected by MM-DD-YY (US Date Format)

Alex Kapustin2021-04-24 10:37:16

Wrote a problem entirely. The second action is the same in essence. Shurik -I also expected the standard, so the parser tried to overload. Here somewhere stupid error and my illiteracy)))

mikemilansky2021-04-24 10:37:16