I am working in Asp.net web api, my model class is follwoing
[Serializable]
public class Workspace
{
private string strID;
public string strName;
public string ID
{
get { return strID; }
set { strID = value; }
}
public string Name
{
get { return strName; }
set { strName = value; }
}
}
I have Following Get Method in controller
public Workspace GetWorkSpace()
{
if (objWorkspace == null)
{
objWorkspace = new Workspace();
objWorkspace.ID = Guid.NewGuid().ToString();
objWorkspace.Name = "Workspace 1";
}
return objWorkspace;
}
I am trying to get this object using Jquery as follows
var uri = 'api/workspace/GetWorkspace';
$(document).ready(function () {
$.getJSON(uri)
.done(function (data) {
$('#workspaceId').append(data.ID);
$('#workspaceName').append(data.Name);
});
});
I get the response object in data, but it exclude my public properties "ID" and "Name" as shown below
strID: "a0a523c6-f657-40df-b957-114b87de02f8"
strName: "Workspace 1"
__proto__: Object
As you see response object get "strID, and strName" , which are private variables in model class, rather it should be ID and Name in reponse data, Moreover, if i remove [Serializable] attribute from my model class, i will get the desired result. Can any one explain me it, and what i do wrong with [Serializable] attribute
your help will be appreciatable