Skip to content

Replies

0
zep lin
zep lin answered on Oct 9, 2014 9:25 AM

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.
Null DateTime Sample

0
zep lin
zep lin answered on Oct 9, 2014 8:23 AM

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.

0
zep lin
zep lin answered on Oct 1, 2014 10:34 AM

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.
 

0
zep lin
zep lin answered on Oct 1, 2014 10:22 AM

Hi,

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.

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.