This is a migrated thread and some comments may be shown as answers.

[Solved] Pass DateTime Picker value to controller

4 Answers 441 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marco
Top achievements
Rank 1
Marco asked on 22 Feb 2010, 11:21 AM
Hello, i'm facing whit one problem when passing the value of datetimepicker to controller.

I'm using a strongly type view with my dto object and i have a controller action that accepts dto as parameter.

Every property loaded from other control different than dateTimePicker are populated, but dateTime Values are equal to C# min date.

 <p> 
                <label for="dataInicio"><%=SIG.App_GlobalResources.Resources.ementa_C_labelDataInico %></label
                <%=Html.Datepicker("DataInicio", DateTime.Now.ToString())%> 
                <label for="dataFim"><%=SIG.App_GlobalResources.Resources.ementa_C_labelDataFim %></label
                <%=Html.Datepicker("DataFim", DateTime.Now.ToString())%> 
            </p> 
            <p> 
                <label for="descricao">descricao:</label> 
                <%= Html.TextBox("descricao") %> 
                <%= Html.ValidationMessage("descricao", "*") %> 
            </p> 

Controller action
    [AcceptVerbs(HttpVerbs.Post)] 
        public ActionResult SaveTempEmenta(Ementa ementa) 
        { 
            return View(); 
        } 


this is a little sample that isn't working.

Another problem related to dateTimePicker is Globalization. I don't understand why my control is in French.

How can i change localization at run time?

Hope someone can help.

Best Regards
 

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 22 Feb 2010, 01:04 PM
Hi Marco,

The name of the datepicker should be the same as the name of the property, which is bind to. In other words if the property is "DataInicio", then the name of the datepicker should be the same. Could you please verify whether the name of the rendered input is the same as the name of the property? If they are different then the value provider of the ASP.NET MVC will not retrieve the send value.

Regards,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Marco
Top achievements
Rank 1
answered on 22 Feb 2010, 01:27 PM
Hello Georgi, 

First of all thks for the reply. you are right thats exactly my problem. after changed the name of the dateTimePicker to the name of the property i was able to return the value of the property in the controller action.

whatever, i'm stuck whit tow other things :

- Localization 
 how can i change telerik mvc extensions culture at runtime?
- ScriptRegistrar
 how can i register custom scripts and the telerik scripts whiteout using the traditional link references? 

if i use the simple  <% Html.Telerik().ScriptRegistrar(); %> the dateTime control starts working normaly, but when i try to register a custom scripts i lose the functionalities of dateTime Control.

I have tried to register all the all scrips using the below method:
        Html.Telerik().ScriptRegistrar().DefaultGroup(group => 
                    group.Add("~/Scripts/DropDownMenu.js") 
                         .Add("~/Scripts/2010.1.218/telerik.common.min.js") 
                         .Add("~/Scripts/2010.1.218/telerik.calendar.min.js") 
                         .Add("~/Scripts/2010.1.218/telerik.datepicker.min.js") 
                ) 
            .Render(); 

But this way only my menu control is working :(

Can you help me accomplish this two things ?

Best Regards
  
0
Georgi Krustev
Telerik team
answered on 23 Feb 2010, 08:16 AM
Hello Marco,

Straight onto your questions:

#1:
Dapicker is globalized when the Globalization(true) is used. If you need to change the culture dynamically, you just need to change the culture of the ASPX page. To localize the human-readable date parsing, you should override some properties of the $.telerik.cultureInfo object. Here you can more information about that.

#2:
The ScriptRegistrar first will check if the path to the file is relative. If it is not it add the defined default path to the value which is passed as a parameter to the Add(...) method. Depending on the given information you can try this code snippet:
<%= Html.Telerik().ScriptRegistrar().DefaultGroup(group =>
                    group.Add("~/Scripts/DropDownMenu.js")
                         .Add("telerik.common.js") // you can try to avoid add telerik scripts if the controls are added without Ajax, because the script registrar will add the required scripts automatically.
                         .Add("telerik.calendar.js")
                         .Add("telerik.datepicker.js")
                )
%>


Best wishes,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Nathan J Pledger
Top achievements
Rank 2
answered on 07 Apr 2010, 12:26 PM
In addition to your help, Georgi, can I just add:

I have also been seeing issues with this. My problem was that my property was in an encapsulated ViewModel pattern within my ViewModel.

This required the "Name" to be qualified, eg. "ConsultantRegistration.DateOfBirth"

Tags
Date/Time Pickers
Asked by
Marco
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Marco
Top achievements
Rank 1
Nathan J Pledger
Top achievements
Rank 2
Share this question
or