[CLOSED] DateTimePicker

  1. #1

    [CLOSED] DateTimePicker

    2 Questions:
    1) is there a viable DateTimePicker option that can bind to a .Net DateTime object?
    2) why can't I bind a TimeSpan object to a TimeFields? Get invalid cast when try to retrieve the value

    Model
    [Field(FieldLabel = "Pickup Date", LabelAlign = LabelAlign.Right)]
            public DateTime PickupDate { get; set; }
    View
    X.TimeFieldFor(m => m.PickupTime).Format("HH:mm"),
    Controller
    TimeField tf = this.GetCmp<TimeField>("PickupTime")
    tf.SelectedTime' threw an exception of type 'System.InvalidCastException'
    Last edited by Daniil; Aug 01, 2013 at 3:51 AM. Reason: [CLOSED]
  2. #2
    Hello!

    Thank you! We are investigating!
  3. #3
    Hi @ehmdb,

    Welcome to the Ext.NET forums!

    Quote Originally Posted by ehmdb View Post
    1) is there a viable DateTimePicker option that can bind to a .Net DateTime object?
    Do you mean a TimeField under "DateTimePicker"? Yes, we should consider a possibility to support a DateTime to bind to a TimeField. Thank you for the question.

    Quote Originally Posted by ehmdb View Post
    2) why can't I bind a TimeSpan object to a TimeFields? Get invalid cast when try to retrieve the value
    Please clarify how do you submit it?

    What about this way?
    http://mvc.ext.net/#/Models/FormPanelFor/
  4. #4
    Apologies, yes I am referring to a TimeFieldFor as follows:

    [Field(FieldLabel = "Pickup Time", LabelAlign = LabelAlign.Right)]
            public TimeSpan PickupTime { get; set; }
    X.TimeFieldFor(m => m.PickupTime).Format("HH:mm"),
    TimeField tf = this.GetCmp<TimeField>("PickupTime");
    submit code is

    X.Button().Text("Save").PaddingSpec("5 5 5 5 ").MarginSpec("0 10 0 0")
                            .DirectEvents(de =>
                            {
                                de.Click.Url = Url.Action("DirectEventSubmit");
                                de.Click.EventMask.ShowMask = true;
                                de.Click.FormID = "FormOrderEntrySummary";
                            })
    Last edited by Daniil; Jul 29, 2013 at 3:31 PM. Reason: Please use [CODE] tags
  5. #5
    Thank you. I reproduced it with the test case below. We will investigate what we can do.

    View
    @model Work2MVC.Models.BindModel
    
    @{
        var X = Html.X(); 
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>
    </head>
    <body>
        @X.ResourceManager()
    
        @(X.Button()
            .Text("Save")
            .DirectEvents(de =>
            {
                de.Click.Url = Url.Action("Submit");
                de.Click.FormID = "FormPanel1";
            })
        )
    
    
        @(X.FormPanel()
            .ID("FormPanel1")
            .Items(
                X.TimeFieldFor(m => m.PickupTime)
            )
        )
    </body>
    </html>
    Model
    using Ext.Net.MVC;
    using System;
    
    namespace Work2MVC.Models
    {
        public class BindModel
        {
            [Field(FieldLabel = "Pickup Time")]
            public TimeSpan PickupTime { get; set; }
        }
    }
    Controller
    using System;
    using System.Web.Mvc;
    using Ext.Net;
    using Ext.Net.MVC;
    using Work2MVC.Models;
    
    namespace Work2MVC.Controllers
    {
        [DirectController]
        public class RazorController : Controller
        {
            public ActionResult Index()
            {
                return View(new BindModel() { PickupTime = DateTime.Now.TimeOfDay });
            }
    
            public ActionResult Submit()
            {
                TimeField tf = this.GetCmp<TimeField>("PickupTime");
                X.Msg.Alert("PickupTime", tf.SelectedTime).Show();
    
                return this.Direct();
            }
        }
    }
    However, I would suggest you to leverage the following way to retrieve the things from POST.
    public ActionResult Submit(BindModel entity)
    {
        X.Msg.Alert("PickupTime", entity.PickupTime).Show();
    
        return this.Direct();
    }
  6. #6
    Quote Originally Posted by Daniil View Post
    Yes, we should consider a possibility to support a DateTime to bind to a TimeField. Thank you for the question.
    Ive just made the following commit to the SVN trunk.

    [UPDATE] Now a TimeField can apply a DateTime property from a Model (related to FormPanelFor and TimeFieldFor helpers).

    [UPDATE] Now a Model's TimeSpan property is bound to a TimeField, instead of a TextField. I.e. it doesn't require a "FieldType=typeof(TimeField)" attribute for the Model's property. (related to FormPanelFor and TimeFieldFor helpers)

    Thank you again for the question.
  7. #7

    Thanks

    Thanks, the recompile works.
  8. #8
    The issue with
    X.GetCmp<TimeField>("PickupTime").SelectedTime
    should be fixed in SVN.

    Thank you again for the report.

Similar Threads

  1. Replies: 5
    Last Post: Feb 07, 2011, 10:42 AM

Tags for this Thread

Posting Permissions