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

[Solved] Date always null on action

4 Answers 137 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ju
Top achievements
Rank 1
Ju asked on 15 Jun 2011, 03:33 PM
Hello,
i'm trying to use the calendar. I'm trying to do quite the same example as the one in demos.
But for any reason the parameter date in my action is always null

Here is my code :
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
 
<h2>Mon Calendrier</h2>
@(Html.Telerik().Calendar()
   .Name("Calendar")
   .Selection(settings => settings
         .Action("SelectAction", new { date="{0}"})
      .Dates(
         new List<DateTime> {
            DateTime.Today.AddDays(-1),
            DateTime.Today.AddDays(2),
            DateTime.Today.AddDays(3),
         }
      )
   )
)
 
@if (ViewData["date"] != null) {     <p>This date was clicked: @ViewData["date"]</p>    }

and my controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
 
namespace GestFormat.Controllers
{
   public class CalendarController : Controller
   {
      //
      // GET: /Calendar/
 
      public ActionResult Index(DateTime? date)
      {
         ViewData["selectedDate"] = ViewData["date"] == null ? DateTime.Now : ViewData["date"];
         ViewData["minDate"] = DateTime.Now.AddDays(-7);
         ViewData["maxDate"] = DateTime.Now.AddMonths(14);
         return View();
      }
 
      public ActionResult SelectAction(DateTime? date)
      {
         ViewData["date"] = date;
         return RedirectToAction("Index");
      }
 
      public ActionResult ReturnContent(string sMsg)
      {
         return Content(Server.HtmlEncode(sMsg));
      }
   }
}

Do you have any idea ?
Thanks

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 16 Jun 2011, 08:49 AM
Hello Ju,

 
You are using ViewData is persisted only in the scope of the Action method. After RedirectToAction ViewData["date"] is truncated. I will suggest you use TempData.

Controller:

public ActionResult SelectAction(DateTime? date)
{
    TempData["date"] = date;
    return RedirectToAction("Index");
}

View:
@if (TempData["date"] != null)
{     <p>This date was clicked: @TempData["date"]</p>    }

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
Ju
Top achievements
Rank 1
answered on 16 Jun 2011, 11:57 AM
Hello thanks for your answer.
I've understood what you mean. Anyway it doesn't solve my problem.
In fact, it's the parameter in the action SelectionDate that is always null . It looks like the view don't know how to send the parameter or anything like that.

Do you have any idea ?
0
Georgi Krustev
Telerik team
answered on 16 Jun 2011, 12:16 PM
Hello Ju,

Please check the attached test project in my attempt to replicate the depicted issue. Everything is fine on my end. 

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
Ju
Top achievements
Rank 1
answered on 16 Jun 2011, 12:51 PM
Strange, the value is also null when i'm using your project.
I've tried on another computer and i have the same thing. I will try on my personnal computer tonight if i have time...
Tags
Calendar
Asked by
Ju
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Ju
Top achievements
Rank 1
Share this question
or