Hi,
I have a grid which has two datetime columns. I am makin my own POST request to the controller and I am sending the 'alltransactions' like this :
var transaction = $("#myCurrencyGrid").igGrid("allTransactions");
$.ajax({ type: "POST", url: "/GeneralLedger/CreateCurrency", data: JSON.stringify({ 'myModel': myModel, 'transaction': transaction }), success: function (data) { .. }, dataType: "json", traditional: true, contentType: "application/json; charset=utf-8" });
In my controller I am getting (01/01/0001 00:00:00) (null datetime) in my grid transaction model although I had selected a valid date from the grids datepicker. Why am I getting null Date in my controller in igtransaction's row property?
In my grid I have setup the columns like this :
.Updating() cs.ColumnSetting().ColumnKey("cur_rt_from_dt").EditorType(ColumnEditorType.DatePicker); cs.ColumnSetting().ColumnKey("cur_rt_to_dt").EditorType(ColumnEditorType.DatePicker);
.Columns()
column.For(x => x.cur_rt_from_dt).HeaderText("From Date").DataType("date").Format("ddd, MMM-d-yy HH:mm"); column.For(x => x.cur_rt_to_dt).HeaderText("To Date").DataType("date").Format("ddd, MMM-d-yy HH:mm");
I console.logged the JSON.stringified() transaction on my submit button click and here is the output:
CONSOLE.LOG : "Stringified transaction: [{"type":"newrow","tid":"447b","row":{"cur_rt_pk":6,"cur_rt_from_dt":"/Date(1411066800000)/","cur_rt_to_dt":"/Date(1411153200000)/","cur_rt_buying_rate":66,"cur_rt_selling_rate":67},"rowId":6}]"
If the '/Date(......)/' are valid dates why am I getting (01/01/0001 00:00:00) in my controller. I just want to point out that I am sending these transactions after JSON.stringify(transaction) and in the console log I can see a differenct /Date(....)/ for every different date so uptil JSON.Stringify function the date is ok ( I think ) . I am using Asp.net MVC & IgniteUI version 4.13.2.2157 . I tried enabling enable Utc date to true and false also, nothing changes. I still get a bogus null date in my controller.
Hello Zep,
Thank you for your patience!
I was able to determine the source of the issue. The grid serializes the dates like ASP MVC, i.e. /Date(ticks)/, because by default the JSON format does not support Date type. (Refer to the following article).Since yo are using custom class for transactions not the default one, your class does not know how to parse this Date format.
The workaround for that is to send the transaction model as JSON string
1
data: JSON.stringify({ 'currencyModel': currencyModel, 'Mode': mode, 'transaction': (transaction.length > 0 ? JSON.stringify(transaction) : null )}),
And then you can parse your Date correctly using the Transaction class
1 2 3 4 5 6 7 8 9 10 11
[HttpPost] public ActionResult CreateCurrency(Currency currencyModel, string Mode, string entityValue, string transaction) { if (transaction != null) { var gridModel = (new GridModel()).LoadTransactions<CurrencyRate>(transaction); ViewBag.Entity = "Currency"; } return Json(new { Success = true, successMessage = "Success" }); }
Please review the attached sample and let me know if I may be of further assistance.
Thank you for the perfect sample!
The issue now reproduces and I am able to investigate its source.I will let you know as soonest I got any updates on this.
Here you go. This sample is completely working and depicts the exact scenario I explained to you.
You need to do the following to inspect my scenario:
1) Insert Breakpoint on CreateCurrency [POST] ActionMethod in Home controller.
2) When the form is rendered Add new row(s) in the grid with dates.
3) Click on Create button
4) Check the transaction parameter of CreateCurrency [POST] method and check the dates inside it.
The dates which were selected as valid dates turn into (01/01/0001 12:00:00) on the controller's transaction parameter.
I am only using Json.Stringify on grid transactions so that I can pass them to the controller, If Json.Stringify is messing up the dates than what could be done to solve it?
Thanks for your time in advance.
Yes Denis, I am still not able to solve this issue. I provided you all the detail I had, Its very tough for me to make an isolated sample because I have too much workload on me right now and in the past when I have managed to provide an isolated sample, unfortunately I got a reply that the sample was not in working condition so therefore my query was not resolved. I will try to provide you an isolated sample but if you can help me out with the current details I gave you it would be great.
Please if you could ask some other resource who might have knowledge about this issue or might be aware of the inner workings of how igGrid handles the date in its transactions, I think that would be helpful. And I will try to provide you an isolated sample as soon as I get a chance, thanks for your concern and help. I appreciate it.
I'm just following up to see if you need any further assistance with this issue. If so please let me know.