RestSharp RestResponse从Controller返回null

时间:2013-09-18 06:58:01

标签: null return deserialization restsharp

我有一个带有get函数的控制器,它将模型返回给客户端,如果我在控制器上调试这个代码,模型属性设置得很好但是当它返回到客户端时它不是null但属性是..我确定它们在返回之前已经设置好了。这是我的控制器代码..

public DiskContentModelList Get([FromUri] string token)
    {
        var myFileList = new DiskContentModelList();
        var account = CheckPermissions(token);
        if (CheckCuenta(account))
        {
            //Mandar todos los archivos de la cuenta                
            var myFiles = new List<DiskContentModel>();

            myFiles.Add(new DiskContentModel(1, "foto", "dir"));
            myFiles.Add(new DiskContentModel(1, "video", "dir"));
            myFiles.Add(new DiskContentModel(1, "music", "dir"));

            myFileList.FileList = myFiles;
            return myFileList;
        }
        return myFileList;
    }

这是我的客户代码..

private void FormFileExplorerLoad(object sender, EventArgs e)
    {
        var myRestClient = new RestClient(@"http://localhost:1840/");
        var myRestRequest = new RestRequest("api/files?token=" + Program.MyToken, Method.GET);
        //myRestRequest.AddUrlSegment("token", Program.MyToken);
        var response = myRestClient.Execute<DiskContentModelList>(myRestRequest);
        foreach (var diskModel in ((DiskContentModelList)response.Data).FileList)
            TreeExplorer.Nodes.Add(new TreeNode(((DiskContentModel)diskModel).Name));       
    }

这是模特..

public class DiskContentModelList
{
    public List<DiskContentModel> FileList;
}

这是这个

的重要示例
// or automatically deserialize result
// return content type is sniffed but can be explicitly set via RestClient.AddHandler();
RestResponse<Person> response2 = client.Execute<Person>(request);
var name = response2.Data.Name;

在本网站http://restsharp.org/

0 个答案:

没有答案