c# - Array becoming empty after receiving into controller with AJAX call -
i have class named someobject contains list of name extras.
am trying pass data via ajax call controller. within data received mvc controller array showing proper length entire data inside array object empty.
is there solution this?
am passing object of class someobject via ajax call this: took via f12 dev tools form data
chk1checked:false chk2checked:true chk3checked:true extras[0][id]:comp1 extras[0][itemtype]:dropdown extras[0][itemid]:111 extras[0][itemvalue]:eval1 extras[1][id]:comp2 extras[1][itemtype]:dropdown extras[1][itemid]:112 extras[1][itemvalue]:eval2
am able see 'extras' variable inside controller length of 2 inside data null.
says have class this
public class { public int id { get; set; } public int itemid { get; set; } public string itemtype { get; set; } public string itemvalue { get; set; } }
try retrieve list matched property's name ..
public actionresult youraction(list<extra> extras, bool chk1checked, //...
data object post via ajax should looks this
{ "extras": [{ "id": 1, "itemid": 1, "itemtype": "foo", "itemvalue": "bar" }, { "id": 2, "itemid": 2, "itemtype": "whatever", "itemvalue": "" }] }
Comments
Post a Comment