When using JavaScript to call a controller and process a function, I encountered an issue where the parameter value (name in summary) is null when the field is set to private. However, the function works correctly when the field is set to public. Is setting it to public the only solution? Or is there a better way to handle this situation? Thank you in advance.
My object
[DataContract]
public class Summary
{
[DataMember]
public int id { private set; get; }
[DataMember]
public string name { private set; get; }
public summary() {}
public summary(int id, string name)
{
id = id;
name = name;
}
}
MVC Controller
public ActionResult SetSummary(Summary summary)
{
string anme = summary.name; **<-- null if private**
...
}
Javascript
$http.post("MyController/SetSummary", JSON.stringify({
summary: mySummaryObject}))
.success(function (data, status, headers, config) {
....
}