0

my jquery script code part , the script is working fine and set data array/object in dataBLL..

var dataBLL = [];
$('#mytable tr').each(function (i) {

dataBLL.push({

id: $(this).find('td:eq(0)').text(),
ctype: $(this).find('td:eq(1)').text(),
cpath: $(this).find('td:eq(2)').text(),
ckey: $(this).find('td:eq(3)').text(),
ckey: $(this).find('td:eq(4) input:frist').val(),

});
  $.ajax ({
             url:"User/BllBtn",
             type:"POST",
             data:"dataBll="JSON.stringify(dataBLL);
             dataType: "json",
             success: function (e) {

                alert("sucess");
            }})

but i am not able to send this object/Array to my controller to use it's data and iterate through each row entry .

My controller signature

[HttpPost]
public ActionResutl BllBtn(List<string> dataBll)
{

}

Please guide how to get this object as list so I can loop into in simplest way.

2
  • what to do then .. any code change requeied @Div Commented Oct 19, 2016 at 8:52
  • getting null in List<string> dataBll :( @Div Commented Oct 19, 2016 at 9:00

1 Answer 1

3

You've got a syntax error (which your browser console will have told you), and also you're producing invalid JSON.

data: { "dataBll": dataBLL }

should work I think. Or

data: JSON.stringify({ "dataBll": dataBLL })

at worst. Also set

contentType: 'application/json; charset=UTF-8'

as another option in the ajax call.

The next problem is you are trying to accept List<string> into your method, but dataBll is a complex object with the following properties:

id, ctype, cpath, ckey, ckey

Firstly, you can't define ckey twice in the same object, and secondly your JSON object is incompatible with the type in the C# method. You need to define a class, e.g.

public class myNewType
{
  public string id {get; set; }
  public string ctype {get; set; }
  public string cpath {get; set; }
  public string ckey {get; set; }
}

and then accept List<myNewType> as the parameter to the method:

public ActionResult BllBtn(List<myNewType> dataBll)
Sign up to request clarification or add additional context in comments.

7 Comments

please help how to produce valid JSON ..any code exaple! @ADyson
no i am not getting any data in my action , only count 1 at index[0] with key names only nothing else :(
any other method you know to if it is working i will follow that @ADyson
Its data: JSON.stringify({ "dataBll": dataBLL }), and you also need to set contentType: 'application/json; charset=UTF-8',
Done it , but again how to get the value in controller ActionResult BllBtn :( @StephenMuecke
|

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.