This is a migrated thread and some comments may be shown as answers.
Calendar Date Format
9 Answers 123 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Fred Chateau
Top achievements
Rank 1
Fred Chateau asked on 15 Nov 2010, 08:45 PM

Apparently, the calendar returns a date in the format:  MM/dd/yyyy

So, when the date is passed to the ActionMethod on the server the routing goes like this:

http://localhost/Controller/Action/11/15/2010

Am I missing something, because this seems a little silly to me? Why use forward slashes to pass a parameter to an MVC method? The parameter never makes it to the controller. It just becomes a bad URL.

Anyway, I imagine I might be able to work this out in routing, but I would very much like to send the following format to the server:

yyyy-MM-dd      As in: 2010-11-15

Would someone please tell me how to format the calendar do this?

9 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 16 Nov 2010, 07:39 AM
Hi Fred Chateau,

 You need to specify a route value like we have done in our select action demo. Then the url would look like this:

http://demos.telerik.com/aspnet-mvc/calendar/selectaction?date=11/19/2010

Regards,
Atanas Korchev
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
Fred Chateau
Top achievements
Rank 1
answered on 21 Nov 2010, 05:55 AM

Well, I fixed it on the client side by using jQuery to format the date, but I still don't understand how you think your URL is supposed to work in MVC.

This URL:

http://demos.telerik.com/aspnet-mvc/calendar/selectaction?date=11/19/2010

Translates to this URL in MVC:

http://demos.telerik.com/aspnet-mvc/calendar/selectaction/11/19/2010

Which causes MVC to look for this URL:

http://demos.telerik.com/aspnet-mvc/calendar/selectaction/11/19

And passes 2010 as the parameter to the controller.

0
Georgi Krustev
Telerik team
answered on 22 Nov 2010, 11:39 AM
Hello Fred,

I have created a simple test project, which shows how calendar should work. Could you please check it and let me know if I am missing something ?

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
Jay Legere
Top achievements
Rank 1
answered on 23 Feb 2011, 03:52 AM
I agree with Fred.  I too am trying to pass a date WITHOUT using the querystring:

http://localhost/Controller/Action/2011-01-20

I have tried a couple of ways to get this behavior:

<%
Html.Telerik().Calendar()
    .Name("Calendar")
    .Value((DateTime)ViewData["SelectedDate"])
    .Selection(settings => settings
        .Action("List", new { id = "{0:yyyy-MM-dd}" }))
    .Render();
%>


and

<%
Html.Telerik().Calendar()
    .Name("Calendar")
    .Value((DateTime)ViewData["SelectedDate"])
    .Selection(settings => settings
        .Action("List", new { id = "{0:yyyy}-{0:MM}-{0:dd}" }))
    .Render();
%>

 

 


but the calendar seems to ignore the formatting.

Is this possible?

Thanks,

Jay

 

 

 

0
Georgi Krustev
Telerik team
answered on 23 Feb 2011, 09:10 AM
Hello Jay,

 
In order to allow ASP.NET MVC to accept URL in this format ... , you will need to define route constraints. You can check this link for more information.

Kind regards,
Georgi Krustev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
nachid
Top achievements
Rank 1
answered on 23 Feb 2011, 12:33 PM
Ideally, the date should have been formatted using the universal ANSI Format CCYYMMDD

And the url should be then
http://localhost/Controller/Action/20110120
This is very clear and there is no possible confusion whatever the culture

Having a date used in an url and formatted with slashes does not make sense and it is very complicated for everyone

Hope this suggestion of using ANSI formant will be incorporated to the next release

0
Jay Legere
Top achievements
Rank 1
answered on 23 Feb 2011, 04:45 PM
Georgi , do you really want me to create a route that looks like this:

routes.MapRoute(
    "DateHandler",
    "{controller}/{action}/{month}/{day}/{year}",
    new { controller = "Home", action = "Index" } 
);

just because we can't have a date without slashes?  And then build up the date in the controller?

date = DateTime.Parse(year + "-" + month + "-" + day);

That's "icky".  Can't we just format the date that the calendar sends? Or as nachid suggest, at least have a universal format the doesn't have slashes in it?

0
Georgi Krustev
Telerik team
answered on 28 Feb 2011, 03:59 PM
Hello Jay,

We further investigate this issue and I am afraid that formatting of the date is supported in current version. 

Nevertheless we will give all our best to implement it for the next official release of Telerik Components for ASP.NET MVC scheduled for the middle of march. For the time being the implementation which you suggested is the only workaround.

Regards,
Georgi Krustev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Mark Liu
Top achievements
Rank 1
answered on 30 Nov 2011, 02:43 AM
I also encounter this problem with data formatting in the calendar control.

Below are my solution, hopefully it will help someone else :)

Brief Background:
I want to render the selection URL to something like:
/controller/list/2011-11-24

So I configure the selection action to:
.Selection(x => x.Action("Index", new { date = "{0:yyyy-MM-dd}" }))

But the calendar render the link as:
/controller/list/2011-00-24

My thought is someone is doing a ToLower on my format string. So it's rendering minutes instead of month. After a few attempt at workaround such as {o:u} for universal date format, I decide to fix the problem at the source.

Solution:
1. Open "C:\Program Files (x86)\Telerik\Extensions for ASP.NET MVC Q3 2011\Source\Telerik.Mvc.sln"
2. Open "Telerik.Web.Mvc\UI\Calendar\Calendar.cs"
3. Find and delete the bold text:

protected override void WriteHtml(System.Web.UI.HtmlTextWriter writer)
{
    ICalendarHtmlBuilder renderer = rendererFactory.Create(this);

    urlFormat = SelectionSettings.GenerateUrl(ViewContext, UrlGenerator);
    if (urlFormat.HasValue())
    {
        urlFormat = HttpUtility.UrlDecode(urlFormat).ToLowerInvariant();
    }

4. Update the assembly version
5. Make a new build for your MVC version
6. Update your project to use the new Telerik.Web.Mvc.dll

I would love to know the reason why the code was converting the UrlFormat to lowercase. Is it for aesthetic reason to sate URLhipster? or are there technical considerations?
Tags
Calendar
Asked by
Fred Chateau
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Fred Chateau
Top achievements
Rank 1
Georgi Krustev
Telerik team
Jay Legere
Top achievements
Rank 1
nachid
Top achievements
Rank 1
Mark Liu
Top achievements
Rank 1
Share this question
or