I have a model class named Parcel which contains the parameters Name and CenterPoint:
public class Parcel
{
public string Name { get; set; }
public object CenterPoint { get; set; }
}
The values for these parameters are obtained from a map. When a parcel is clicked, the center point is calculated and stored in a JavaScript variable. The CenterPoint is represented as a JSON object, while the Name is plain text.
I need to save the CenterPoint as a JSON object in the database so that it can be retrieved and drawn on the map later.
However, when I post the data to the action method as shown below, the CenterPoint object appears as {object}:
It should actually look like this: { type="point", x=121.32380004076, y=452.024614968}
[HttpPost]
public ActionResult SaveParcel(Parcel parcel)
{
return Json(new {parcel}, JsonRequestBehavior.AllowGet);
}
My JavaScript code snippet is here:
var postData = {
"Name": document.getElementById("name").value,
"CenterPoint": document.getElementById("center").value
};
$http({
method: 'POST',
url: "/Parcel/SaveParcel/",
data: postData,
}).success(function (data, status, headers, config) {
console.log(data);
});
I am looking for a way to store and retrieve the JSON data accurately. Is there a better approach available?