0

passing Json Array to MVC Controller Action returning Null .

**controler*** 
public class TestData
{
    public string name1  { get; set; }
    public string value1 { get; set; }   
}

public JsonResult MyMethod(List<TestData> testVal)
    {
 //testval object having name1 and value1 null values
  }

view page

      $.getJSON("/viewFolderName/MyMethod",
         {
             testVal: [{ name1: "veea", value1: "0" }]

         },
         function (data) {
         //result
         });

passing Json Array to MVC Controller Action returning Null

3

1 Answer 1

0

No, don't try to be sending JSON in a GET request. Use JSON with other verbs which have body, such as POST and PUT.

$.ajax({
    url: '/viewFolderName/MyMethod',
    type: 'GET',
    data: { testVal: [{ name1: "veea", value1: "0" }] },
    traditional: true,
    success: function (result) {
        console.log(JSON.stringify(result));
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.