Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数据访问:尝试通过本地主机访问_C#_.net_Visual Studio_Rest - Fatal编程技术网

C# 数据访问:尝试通过本地主机访问

C# 数据访问:尝试通过本地主机访问,c#,.net,visual-studio,rest,C#,.net,Visual Studio,Rest,我目前正在通过xamarin表单开发一个应用程序。在此应用程序中,有必要使用后端解决方案。为了能够模拟这一点,我使用efcore创建了一个restapi作为内存中的数据提供者。restapi函数很好,我已经用postman测试过了 然后,我的目标是将这个RESTAPI中的信息显示到我的iphone模拟器中。我已在我的xaml文件中设置了一个listview,并试图通过我的代码隐藏文件访问我的数据: public partial class testing_backendPage : Conten

我目前正在通过xamarin表单开发一个应用程序。在此应用程序中,有必要使用后端解决方案。为了能够模拟这一点,我使用efcore创建了一个restapi作为内存中的数据提供者。restapi函数很好,我已经用postman测试过了

然后,我的目标是将这个RESTAPI中的信息显示到我的iphone模拟器中。我已在我的xaml文件中设置了一个listview,并试图通过我的代码隐藏文件访问我的数据:

public partial class testing_backendPage : ContentPage
{
    private const string Url = "http://localhost:5000/user/";
    private HttpClient _client = new HttpClient();
    private ObservableCollection<Post> _posts; 

    public testing_backendPage()
    {
        InitializeComponent();
    }

    protected override async void OnAppearing()
    {
        var content = await _client.GetStringAsync(Url);
        var posts = JsonConvert.DeserializeObject<List<Post>>(content);
        _posts = new ObservableCollection<Post>(posts);
        postsListView.ItemsSource = _posts; 
        base.OnAppearing();
    }
公共部分类测试\u后端页:ContentPage
{
私有常量字符串Url=”http://localhost:5000/user/";
私有HttpClient _client=新HttpClient();
私人可观察收集站;
公共测试_backendPage()
{
初始化组件();
}
受保护的重写异步void OnAppearing()
{
var content=await\u client.GetStringAsync(Url);
var posts=JsonConvert.DeserializeObject(内容);
_posts=新的可观察集合(posts);
postsListView.ItemsSource=\u posts;
base.OnAppearing();
}

当我运行程序时,一切运行正常,但是数据没有显示。

var content
行上添加一个断点,并与我们分享错误消息我也遇到了同样的问题。我用两种方法解决了这个问题:我在我的开发服务器上用一个公共
Url
更改了
Url
;我添加了一个
ViewModel
并n it我读取数据。如果您需要更多信息…@prtdomingo添加了断点,但没有发现错误消息。是否可以通过某种方式读取当前值?@Enrico如何将数据传递到xaml文件。我首先尝试使用lisview,但未出现数据,然后尝试使用label,但仅显示类的名称,而不是实际的内容t、 有什么想法吗?