Ulhas Tuscano
Ulhas Tuscano

Reputation: 5620

How to send data to controller through AJAX+HTTPPost

I am developing a webpage where in i have a form which contains 2 text boxes & a dynamically generated table using jquery. The dynamic table contains only one column 'Name'. I want to send all the data to my controller??

Upvotes: 0

Views: 70

Answers (2)

kpull1
kpull1

Reputation: 1653

Use a POST (i.e. $.post) to send your data serialized in a JS object to the controller:

$.post({
  type: "POST",
  url: "MyController/MyAction",
  data: serializedData,
  success: successFunction
});

Recover the data in your controller:

public class MyController : Controller {
  [HttpPost]
  public string MyAction(List<string> serializedData) { }
}

Upvotes: 1

Dev
Dev

Reputation: 6776

Use Textbox/Hidden insde the column and get data on these textbox/hiddens. All should be same name eg. name="dummy". Now on submit to controller get them as

Request.Form("dummy");

Please clarify your requirement if this is not so.

Upvotes: 1

Related Questions