Brave Soul
Brave Soul

Reputation: 3620

Jquery send data to controller method from $().Load()

First try to relate the things. I have a dynamic created div which I was loading from $().Load() something like this

 $(elem).load("BarChart");

Note: elem id dynamically created div at the same moment

untill this all working fine but now I want to send selected Data

something like this

       $(elem).load("BarChart",{Values: values});

Note: BarChart is Partial View. which is calling Controller Method but not able to find the values passed from load

controller Method

 public ActionResult BarChart(List<String> Values)
        {
            foreach (var v in Values)
            {
                lstPointSeries = Utility.GetPointSeries(Session["DbName"].ToString(), Session["AccountGroupName"].ToString(), null, AggregrationType.Total, v, null);
            }
            ViewBag.pointSeries = lstPointSeries;

            return PartialView();
        }

Note: Values is null

EDIT:

var values are list of selected checkbox from UI. like this something like this

values = ["first","second","third","fourth"];

var values = $('input:checkbox:checked.XAxisrowCheckbox').map(function () {
            return $(this).closest('td').next().text();
        }).get();

Upvotes: 0

Views: 608

Answers (1)

Narek Arzumanyan
Narek Arzumanyan

Reputation: 616

I tried your code, and it works fine

Try this:

url = urlHelper.CommonHelper("", "About", "TestAction");
$("#TestDivId").load(url, { Values: ["aaa","bbb"] });
public ActionResult TestAction(List<string> Values) { return View(); }

enter image description here

Upvotes: 2

Related Questions