Strange Formatting Issue

4 posts, 0 answers
  1. Louis
    Louis  avatar
    14 posts
    Member since:
    Mar 2011

    Posted 08 Apr 2014 Link to this post

    I have a reusable view for displaying project information in a handful of places.  In two places, I use this view to update a model and send it to the server for processing.  I'm seeing some strange formatting issue with the DatetimePicker when the same view is used on different pages (see attached screenshots).  I don't explicitly apply a format string to the Datepicker, but even having done so it doesn't make a difference.  If I edit the value, the format gets applied, but on load it is incorrect.  Both of the views are being called slightly different from my controller, but return the same partial with the same model:

    [HttpPost]
    public ActionResult UpdateView(Project project)
    {
        var pipelineProject = project;
        ViewBag.IsUpdate = true;
        return PartialView("_CreateUpdateProject", pipelineProject);
    }
     
     
    [HttpPost]
    public ActionResult UpdateViewForProjectDocumentGuid(string projectDocumentGuid)
    {
        var projectRepository = new ProjectRepository(SystemConnection, CurrentUser, WebConfigHelper.GetConfigurationValue("DefaultProgram"));
        var pipelineProject = projectRepository.Read(new ProjectSearchModel() { AccountNames = AccessibleProjects.Select(a => a.ProjectAccountName).ToList(), DocumentGuid = projectDocumentGuid}).First();
        ViewBag.IsUpdate = true;
        ViewBag.CollapseGeneral = true;
        return PartialView("_CreateUpdateProject", pipelineProject);
    }

    The GoodDatepickerFormat image comes from result of UpdateViewForProjectDocumentGuid and the BadDatepickerFormat comes from UpdateView,  Everything looks the same in both cases (other than UpdateView returning the DateTimes in question with a Kind of Local rather than Unspecified), and I attempted to read it exactly the same as the working case but that made no difference.  Is there any workaround to force format on the field?

  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 10 Apr 2014 Link to this post

    Hello Louis,

    We assume this is happening because you are posting values for those two fields that the DateTimePickers present. And since this is the format in which they are posted the ModelState returns the same string representation.

    Try to clear the ModelState dictionary in the action method and see if it makes a difference.

    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.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Louis
    Louis  avatar
    14 posts
    Member since:
    Mar 2011

    Posted 10 Apr 2014 in reply to Petur Subev Link to this post

    Petur,

    I swapped the incorrectly formatted Controller action to take in the model from the POST and read a fresh version of it (just like the second controller in the example above) and the result is the same.  For a bit more context, I return the '_CreateUpdateProject' partial view in both cases and the partial view has a subsequent partial view where these DatePickers exist.  This still doesn't explain why the behavior is different in both places, when the content of the return is identical.

    As a workaround I decided to format the fields myself on document ready and noticed that the datePicker.value() is null, while the datePicker.element[0].defaultValue contains the correct value.  It seems as if the element isn't bound correctly, and it falls back to the defaultValue.  In order to force formatting I do the following on document ready:

    var finishDatepicker = $("#PipelineScheduleFinishDate").data("kendoDatePicker");
    var finishDate = new Date(finishDatepicker.element[0].defaultValue);
    finishDatepicker.value(finishDate);

    var
    startDatepicker = $("#PipelineScheduleStartDate").data("kendoDatePicker");
    var startDate = new Date(startDatepicker.element[0].defaultValue);
    startDatepicker.value(startDate);


    This results in the value being formatted properly.
  5. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 14 Apr 2014 Link to this post

    Hello Louis,

    How exactly do you submit that form to the server, is it through Ajax? We assume this is happening because you post the value through Ajax (this is the UTC date format) and then you do not clear the ModelState and the value appears like this.

    We will need a small replication within a sample project to investigate and give a concrete resolution to the case.

    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.

     
Back to Top
UI for ASP.NET MVC is VS 2017 Ready