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 contacting Infragistics Developer Support!
I suggest you specifying updateUrl and using the saveChanges method of igGrid. This way the grid handles automatically the ajax and how the data is passed to the controller.Review the attached sample and let me know if you have any additional questions.
If you process myModel before passing it to the ajax method and that is the reason why you use ajax to update the data to the server,please provide myModel value and what is your final goal.
Reason why I dont use updateUrl & saveChanges() :
I purposefully ignored the udpateUrl method because of some shortcomings of this method. The updateUrl method makes a separate ajax request to the server and because the form's data is not part of the Grid Model, so that needs to be posted separately which could result in some issues for example if the POST request of UpdateUrl succeeds in being posted but the form itself returned with errors or the server did not respond, this would result in the grid data(Model's Detail) being posted to the databse and its form data(Model's Master) not being posted hene resulting in bogus entries in details table and no entry of its master in master table. I also opted out of the UpdateUrl method because my Ajax request of grid's UpdateUrl post method was being cancelled by browser because before it was finished,my form's MVC POST method was making a sycnhronous request at the same time(because both were binded on the same button click) therefore UpdateUrl was not working for me. The reason why I opted out of the UpdateUrl method is also described in this forum post :
http://ko.infragistics.com/community/forums/t/91815.aspx
http://ko.infragistics.com/community/forums/p/91823/453846.aspx#453846
This is the reason I make a single POST request manually and I send the Form's data (master) as well as grid's transactions (Detail) in a single POST request. This way I can get both of these at one place and if one fails to submit I can also cancel the other one and vice versa in my controller.
-----------------------------------------
And yes, I process myModel before passing to the Ajax, I just didnt want to paste all of my code here. For clarification here is the complete Ajax request which I make with form's model as well as grid transactions :
if (formIsValid) { var transaction = $("#myGrid").igGrid("allTransactions"); //Grid transactions myModel = $('#form').serializeObject(); //Form's model (Serialize Object is my javascript function) console.log("Stringified transaction: " + JSON.stringify(transaction)); $.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" }); }
$.fn.serializeObject = function () { var o = {}; var a = this.serializeArray(); console.log(a); $.each(a, function () { if (o[this.name] !== undefined) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; };
-------------------------------------------------------------------
My final goal is to post the form's data (myModel) as well as grid transactions (Detail of myModel) to the controller. The form is posted succeffully but the dates are not being passed correctly and the date I get on my controller is not what I selected through the grid's datepicker. Whatever date I select from grid's datepicker, I get null date (01/01/0001 00:00:00) on my controller in 'transaction' parameter of my action method. I think you get my point.
If I have to process the dates inside the grid transactions before sending them through Ajax, how can I do that? The date is in this format on client side /Date(......)/ . Do I have to convert it into string before sending? Will this string automatically cast itself into c#'s DateTime datatype or will it remain a string? Any help would be appreciated.
Thanks.
Also one more thing, Serialize object is being called on my form (myModel) and NOT the grid transactions. The dateTime columns are part of the grid transactions therefore they are not being processed by the serializeObject function. I am only using Json.Stringify on grid transactions so that I can pass them to the controller.
This is the signature of my controller's action method which is called by the ajax request. This method gets all the data correctly, only the dates are not correct.
public ActionResult CreateCurrency(myModel myModel , List<GridTransaction/<myModelDetail/>> transaction)
transaction gets every transaction in it , but the dates are not correct.
Hello Zep
Thank you for the provided information!
I tried to reproduce your issue, but I do not have success so far. could you please modify my sample from my previous reply, so it reproduces the issue and attach in your reply.
Thank you in advance!
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.
hello ,
I am using igDatePicker in Html.Infragistics().Grid()
1. column.For(x => x.Col1).HeaderText("Col1").Width(colWidth).DataType("date").Format(dateformat).Hidden(false).HeaderCssClass("GridHeader");
2. settings.ColumnSetting().ColumnKey("Col1").AllowFiltering(true).FilterCondition("startsWith");
3. .ColumnSettings(cs =>
{
cs.columnSetting().ColumnKey("Col1").EditorType(ColumnEditorType.DatePicker).Required(true).Validation(true);
}
4. .AddClientEvent("editCellStarting", "editCellStarting");
5
function editCellStartingEvent(evt, ui) {
var endDate = grid.igGridUpdating("editorForKey", "Col8");
$($endDate.igEditorFilter("option", "provider").editor.element).data("igDatePicker").options.minValue = ui.newValue;
)
6. grid.on("iggridupdatingdatadirty", function (event, ui) {
grid.igGrid("commit");
return false;
});
6. grid.igGrid("saveChanges", function saveSuccess(data) {}
on serve side i am not getting the correct formate of date. date is comming in "/Date(1510733103000)/"
that formate.
also error "This option can not be set runtime" showing while loading the Grid
I am using igDatePicker in Html.Infragistics().Grid<MyModel>()
I am glad I have managed to help you resolving this.
If you need any further assistance do not hesitate to contact me.
Just implemented it. Working perfectly. Thanks again.
Thanks alot Denis, I have not yet ran the sample but I think this will solve it. I will get back to you after implementing it tomorrow morning. Thanks for your help. Really appreciate it.