0

I want to transfer datetimepicker value to my controller. I am able to transfer value by regular:

     //PassDate Value While Calling Main Controller.
    vrdCurv = "@Url.Action("GetOutgoingMessage", "OutGoingMessages", new { ABC = "asdnfsdf" })";

But not able to get result from the below code.

  //******Start of Date Pickers************
    var datepickerFrom = $("#dateFromPicker").kendoDatePicker({
        format: "dd/MM/yyyy",
        change: function () {
            datepickerTo.min(datepickerFrom.value());
        },
    }).data("kendoDatePicker");

  //PassDate Value While Calling Main Controller.
    vrdCurv = "@Url.Action("GetOutgoingMessage", "OutGoingMessages", new { dateTimePicker.value })";

//Controller Code:

     [HttpGet]
    public JsonResult GetOutgoingMessage(string ABC)
    {
    var a = abc;

    }

I also tried to pass normal variable value as below code that is also not working:

   [HttpGet]
    public JsonResult GetOutgoingMessage(DateTime? abc)
    {
        using (var db = SiteUtil.NewDb)
        {

             TempData["msg"] = abc;
          }
    }

//Jscript:

    var fromDate = null;
    var toDate = null;

    //Inilialise date variable.

    fromDate = '2015-07-10';
    toDate = '2015-07-10';

    var dataSourceOutMessage = new kendo.data.DataSource({
            transport: {
            read: {
                url: "@Url.Action("GetOutgoingMessage", "OutGoingMessages")",
               dataType: 'json',
               date:{"fromdate" : fromdate}
        }
    },
        schema: {
      model: {
      fields:
     {
     Id: { type: "String" },
     MsgType: { type: "String" },
     Subject: { type: "String" },
     CreatedOn: { type: "String" },
    ProcessedOn: {type: "date"}
   }
   }
   },
   pageSize: 20
   });
albert
  • 8,285
  • 3
  • 19
  • 32
Mack Patel
  • 25
  • 3
  • 13
  • 1
    `@Url.Action()` is razor code which is evaluated on the server before its sent to the view. You can't use `new { dateTimePicker.value }` - because `dateTimePicker` does not exist on the server. You need to use ajax to post the value –  Sep 04 '15 at 07:04
  • I have tried to pass normal variable that is also not working. – Mack Patel Sep 04 '15 at 07:21
  • You need to show the code you have tried –  Sep 04 '15 at 07:21

1 Answers1

0

Can you try this:

 vrdCurv = "@Url.Action("GetOutgoingMessage", "OutGoingMessages", new { ABC = "-1"})";
 vrdCurv.replace("-1", datepickerFrom.value());

(dirty but I think this will work)

I strongly recommend you to go start learning from start ASP.NET MVC here.

jomsk1e
  • 3,585
  • 7
  • 34
  • 59
  • Thanks for the link. I'll follow this link for sure. – Mack Patel Sep 04 '15 at 08:15
  • Thanks. Yes its working. But I also got the solution. Problem was Parameters names. That should be same in both side Either Controller or view. I did same and Got solution. It's woking now. – Mack Patel Sep 07 '15 at 13:35