Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
530
Problems DatePicker (no heading line / getvalue to controller)
posted

Problems igDatePicker

Hi,

I use jQuery igDatePicker in MVC3 Razor vbhtml  according to the following example:

http://localhost:1027/samplesbrowser/date-picker

And I get 2 problems:

a) the datepicker headline with the month name and the 2 symbols "<" (previous month) and ">" (next month) is missing.

I do not know, if a java script reference is missing there or something else.

 

b) I need to transfer the chosen datepicker value to my controller class.

For usual textboxes you can use the "name"-Attribut as parameter in the controller class: e.g.

In the view: @Html.TextBox("txtDatum", Now.Day & "." & Now.Month & "." & Now.Year)

And in the controller class: Function Index(txtDatum As String) As ViewResult         

So the value of "txtDatum" is tranferred to the controller class.

But in Infragistics, there is only "ID" field and no "name" field, inputname does not work.   

@Html.Infragistics.DatePicker().InputName("datepicker1").ID("datepicker1") etc...

Can you tell me, how it is possible to transfer the datepicker value from the view to the controller ?

 

Thanks in advance !!!

Parents
No Data
Reply
  • 24497
    posted

    Hi Tobias,

    The initializers of DatePicker without a parameter or with DatePickerModel parameter can not use default framework of Mvc related to persistance. The client value actually comes to server as HttpContext.Request.Form[id] or similar, but Mvc framework is not able to make use of that. If application needs to get value from client, then it should use Mvc standard initializers like DatePickerFor(expression) or DatePicker(string).

    For example, if application model has fields like

    public class MyModel
    {
     public DateTime Date1 { get; set; }
     public DateTime Date2 { get; set; }
     public string DateString { get; set; }
    }

    and its view creates editors like

     

    <%: Html.Infragistics().DatePickerFor(m => m.Date1).Render() %>
    <%: Html.Infragistics().DatePicker("Date2").Render() %>
    <%: Html.Infragistics().DatePicker("DateString").Render() %>
    <%: Html.Infragistics().DatePicker().ID("DateString2").Render() %>

    then within a controller, an application may get client values as following

    [HttpPost]
    public ActionResult MyAppAction(MyModel model, string returnUrl)
    {
      DateTime date1 = model.Date1;
     DateTime date2 = model.Date2;
     
    string dateString = model.DateString;
     
    string dateString2 = HttpContext.Request.Form["DateString2"];
     ...
    }

    Note: if string-field is used by application model for DatePicker, then client value will come as 7 date fields in format: yyyy-M-d h:m:s.f. For example: 2012-8-21 0:0:0.0. It means that application should do some efforts to extract date fields and make sense of them. So, it is prefferable to use model-field with type of DateTime.

Children