I have the following javascript code:
var groupArray = [];
groupArray.push($("#group").val());
var sendInfo = { Id: 0,
Name: $("#disc-name").val(),
Groups: groupArray,
Description: $("#disc-description").val()
};
$.post('/Home/Add', sendInfo, function(msg) { alert(msg.data }, 'json');
The Controller:
[HttpPost]
public JsonResult Add(Something parameters) {
return Json( new {
data = _something.AddSomething(parameters)
},
JsonRequestBehavior.AllowGet);
}
and Something model is:
public string Name {
get;
set;
}
public List<string> Groups {
get;
set;
}
public int Id {
get;
set;
}
public string Url {
get {
return FriendlyUrl.Slugify( this.Name );
}
}
public string Description {
get;
set;
}
In debug mode, when I want to send sendInfo object via AJAX, I see that Groups is null (in Controller page).
I want to know if something is wrong or is other way to do tricks in Javascript code. I don’t want to change the Something model structure.
Thank you
You should use
JSON.stringifylike this