[CLOSED] Model DateField on submit returns null

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Model DateField on submit returns null

    Hello
    What could be a problem when DateField won't bind from form? If I have for example view like this:
    @model TestSubmit.Models.MyObject
    
    @(Html.X().Window().Width(450).Title("My object")
       .Items(
            Html.X().FormPanel().AutoDataBind(true).ID("FormPanel1").Frame(true).DefaultAnchor("100%").BodyPadding(6)
            .Items(
                Html.X().HiddenFor(m=>m.IDProperty),
                Html.X().TextFieldFor(m => m.StringProperty).ID("firstControl").SelectOnFocus(true),
                Html.X().CheckboxFor(m=> m.BooleanProperty),
                Html.X().DateFieldFor(m=> m.DateProperty),
                Html.X().TextFieldFor(m=> m.IntegerProperty),
                Html.X().TextFieldFor(m=> m.FloatProperty)
            )
         .Buttons(
            Html.X().Button().ID("OK").Text("Ok").Icon(Icon.Disk)
            .DirectEvents(de =>
            {
                de.Click.Url = Url.Action("Submit");
                de.Click.EventMask.ShowMask = true;
                de.Click.FormID = "FormPanel1";
                de.Click.Success = "this.up('window').close();";
            })
            ,
            Html.X().Button()
            .Text("Cancel")
            .OnClientClick("this.up('window').close();")
         )
        )
    )
    On action Submit:
    public ActionResult Submit(MyObject myObject)
    I get DateProperty as null. All other properties are bound well...
    Last edited by Daniil; Oct 06, 2015 at 12:07 PM. Reason: [CLOSED]
  2. #2
    Hi @ingbabic,

    Well, it is either not sent from a client (or wrong value) or it cannot be deserialized on server. But why it happens I don't quite have any at the moment.

    This example looks to be the same/similar as your setup and it works well.
    http://mvc2.ext.net/#/Models/Submit

    Could you, please, check in a request if a DateField's is being submitted or not?
  3. #3
    Here is what I see in Firebug console for submit parameters:
    BooleanProperty
    false
    DateProperty
    1.10.2015.
    FloatProperty
    345,2
    IDProperty
    327dabf4-8aee-453d-8e6d-2cd4d6b6f93b
    IntegerProperty
    11
    StringProperty
    ingbabic
    Source
    IDProperty=327dabf4-8aee-453d-8e6d-2cd4d6b6f93b&StringProperty=ingbabic&BooleanProper ty=false&DateProperty
    =1.10.2015.&IntegerProperty=11&FloatProperty=345%2 C2
  4. #4
    Okay, the date is being submitted.

    Please post the Model class.
  5. #5
    Here is the modela class:
        public class MyObject
        {
            private static List<MyObject> _allObjects;
    
            static MyObject()
            {
                _allObjects = new List<MyObject>() 
                {
                    new MyObject(){ IDProperty=Guid.NewGuid(), StringProperty = "string1", BooleanProperty = false, DateProperty=DateTime.Now, FloatProperty=123.2F, IntegerProperty=18},
                    new MyObject(){ IDProperty=Guid.NewGuid(), StringProperty = "string2", BooleanProperty = true, DateProperty=DateTime.Now.AddDays(-1), FloatProperty=234.2F, IntegerProperty=19},
                    new MyObject(){ IDProperty=Guid.NewGuid(), StringProperty = "string3", BooleanProperty = false, DateProperty=DateTime.Now.AddDays(1), FloatProperty=345.2F, IntegerProperty=11},
                    new MyObject(){ IDProperty=Guid.NewGuid(), StringProperty = "string4", BooleanProperty = true, DateProperty=DateTime.Now.AddDays(-2), FloatProperty=456.2F, IntegerProperty=13},
                    new MyObject(){ IDProperty=Guid.NewGuid(), StringProperty = "string5", BooleanProperty = false, DateProperty=DateTime.Now.AddDays(-3), FloatProperty=567.2F, IntegerProperty=15}
                };
            }
    
            public Guid IDProperty { get; set; }
            [Required(ErrorMessage="This may not be empty")]
            public string StringProperty { get; set; }
            [DefaultValue(false)]
            public bool BooleanProperty { get; set; }
            public DateTime? DateProperty { get; set; }
            [DefaultValue(0)]
            public int? IntegerProperty { get; set; }
            [DefaultValue(0)]
            public float? FloatProperty { get; set; }
    
            public static List<MyObject>GetAll()
            {
                return _allObjects;
            }
        }
    I have impression that it has to do something with regional settings and date. I am trying to run this sample on Windows 10 (fresh installed), and on old Windows 8.1 it is working.
  6. #6
    I have impression that it has to do something with regional settings and date.
    Probably, it might be.

    Please post the Page Sources (Ctrl+U in a browser).

    Also do you have any locale setting in Web.config?

    Please try to add this into Web.config and retest. Is the issue still reproducible?
    <globalization culture="en-US" />
  7. #7
    Please try to add this into Web.config and retest. Is the issue still reproducible?
    <globalization culture="en-US" />
    Well, that was it. Interesting that it was not needed in Windows 8.1, and in Windows 10, without this setting it couldn't work.
    Thank you very much :)
  8. #8
    Could you, please, still post the Page Sources when there is no such setting? Maybe, I will be able to understand what is going wrong.
  9. #9
    Sure I can.
    Just when I should press ctrl-U and take code? Full sample is having a grid panel filled with data from model. On grid panel I have a context menu, where I open a window form with data from selected row. Problem occurs when I press OK on that form (it should update model data and selected row in grid). So when I should pres ctrl-U? (see screenshot)

    Click image for larger version. 

Name:	sample.jpg 
Views:	72 
Size:	103.9 KB 
ID:	24256
    Last edited by ingbabic; Oct 01, 2015 at 2:53 PM. Reason: Added picture
  10. #10
    Just when I should press ctrl-U and take code?
    Please do that when the page is loaded into a browser. In my understanding any actions on a page doesn't affect its sources.
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: Mar 14, 2013, 3:37 PM
  2. Replies: 7
    Last Post: Aug 23, 2012, 6:55 AM
  3. [CLOSED] DateField IsEmpty always returns false
    By brettmas in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Sep 23, 2010, 1:29 AM
  4. [CLOSED] #{AjaxMethods} returns null
    By Steve in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: May 14, 2009, 7:22 AM
  5. [CLOSED] datefield always returns min value
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 30, 2009, 8:22 AM

Tags for this Thread

Posting Permissions