JSON in JsAction Method

Jan 6, 2012 at 1:50 PM

Hi,

Thanks for such a wonderful tool.

I wanted to send JSON to the controller action method. But all the time, it is showing as null value.

Please find the example below.

$(document).ready(function () {
    
var jsonData = "{ "Id" : "1", "Name" : "Naren"}";

var ret = JsActions.MyTestMethod(jsonData); });

 

[JsAction]

  public ActionResultMyTestMethod(TestClass obj)

{

return View();

}

Can you please let me know, if i need to do anything to make the above work.

Thanks,

-Naren

Coordinator
Jan 6, 2012 at 5:54 PM

Hi,

thank you for your post.
The issue you're describing has been already set as a work item.

I am working actively on this bug, it's all due to content encoding.
Release 0.4 fill fix this (and another bug).

Thank you for your patience,

Vincenzo Chianese.

Coordinator
Jan 6, 2012 at 8:21 PM

Hello again,
after some pressure, the issue has been solved into 0.3.1 release.
Check the documentation for understand what was going wrong.
Sorry for the delay; please spread the project, do not have fear to open discussion or ask something!

Vincenzo Chianese.

Jan 9, 2012 at 11:12 AM
Edited Jan 9, 2012 at 11:24 AM

Thanks Vincenzo Chianese for instant response!!

I've tested JSON stuff with JsAction, its working like a charm. Thanks Again.

But when i tried with array of JSON objects, it is throwing a javascript error "Microsoft JScript runtime error: Unexpected quantifier" in JsAction?data file.

Please find my code below.

 var employees = [{ "firstName": "John", "lastName": "Doe" }, { "firstName": "Naren", "lastName": "Vendi"}];

  var ret = JsActions.TestJsAction(employees, {
            success: function (data) {
                alert(data);
            }
        });

Controller

 [JsAction()]
        [HttpPost]
        public string TestJsAction(List<Student> employees)
        {
            // return "Response in " + obj.Name ;

            return "Sucess";
        }

 

Please let me know, am I doing right way.

Thanks,

-Naren

 

 

Coordinator
Jan 9, 2012 at 6:44 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Jan 9, 2012 at 6:44 PM
Edited Jan 9, 2012 at 6:51 PM

You're right, there was a bug in javascript generation (damnet quoted).
It has been fixed in 0.3.2 and should now work with your array (personally tested).
Sorry for the bug. Spread the project!
Vincenzo Chianese

Jan 9, 2012 at 8:58 PM

Thanks again!!

I've tested with JSON Array, it's working good.

Thanks,

-Naren