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
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
Atanas Korchev
the Telerik team
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.
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
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
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.
Georgi Krustev
the Telerik team
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
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?
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.
Georgi Krustev
the Telerik team
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?