Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.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
Javascript Blazor Web程序集未返回控制器中捕获的DB行_Javascript_C#_Html_Asp.net Core_Asp.net Mvc 4 - Fatal编程技术网

Javascript Blazor Web程序集未返回控制器中捕获的DB行

Javascript Blazor Web程序集未返回控制器中捕获的DB行,javascript,c#,html,asp.net-core,asp.net-mvc-4,Javascript,C#,Html,Asp.net Core,Asp.net Mvc 4,我试图从我的Razor代码向我的控制器发出请求,并返回我知道我在DB中的一行 独家新闻-我在我的剃须刀中进行GET调用->它进入我的控制器,在那里我知道它返回我的1db行。所以后端的一切看起来都很好。然后我将其返回到我的前端,但是从GET到我的控制器的数据不在那里,它只包含我放入对象中的原始数据 这是一个Blazor Web Assembly应用程序,所以我已经在浏览器中完成了前端的所有调试,并对任何后端进行了VS调试,以查看发生了什么。但我不知道这里有什么交易 这里发生了什么事 /*Razr

我试图从我的Razor代码向我的控制器发出请求,并返回我知道我在DB中的一行

独家新闻-我在我的剃须刀中进行GET调用->它进入我的控制器,在那里我知道它返回我的1db行。所以后端的一切看起来都很好。然后我将其返回到我的前端,但是从GET到我的控制器的数据不在那里,它只包含我放入对象中的原始数据

这是一个Blazor Web Assembly应用程序,所以我已经在浏览器中完成了前端的所有调试,并对任何后端进行了VS调试,以查看发生了什么。但我不知道这里有什么交易

这里发生了什么事

/*Razror C#*/
私人清单项目;
私有int Id{get;set;}=0;
私有字符串名称{get;set;}=”“;
私有字符串描述{get;set;}=”“;
受保护的重写异步任务OnInitializedAsync()
{
items=wait Http.GetJsonAsync(APIServer);
//值-0
int testID=items.ElementAt(0.Id);
值-“”
字符串testNAME=items.ElementAt(0).Name;
值-“”
字符串testDES=items.ElementAt(0).Description;
}
....
/*控制器*/
[HttpGet]
公共异步任务GetAsync()
{
List currentIems=新列表();
currentItems=await_dbContext.Item.ToListSync();
//这实际上返回了我在数据库中的1行
退货项目;

}
这是一个正在运行的演示,您可以参考:

物品,剃须刀

结果

@page "/Items"
@inject HttpClient Http

<div>
@if (items == null)
{
    <div>Loading...</div>
}
else
{
    <table>
        <thead>
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>Description</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>@items.ElementAt(0).Id</td>
                <td>@items.ElementAt(0).Name</td>
                <td>@items.ElementAt(0).Description</td>
            </tr>
        </tbody>
    </table>
}
</div>

@code {
  private List<Item> items;

  private class Item
  {
    public int Id { get; set; } = 0;
    public string Name { get; set; } = "";
    public string Description { get; set; } = "";
  }


  protected override async Task OnInitializedAsync()
  {
    items = await Http.GetJsonAsync<List<Item>>("https://localhost:44370/api/test");
  }
}
[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
    public readonly WebAPIDbContext _dbContext;
    public TestController(WebAPIDbContext dbContext)
    {
        _dbContext = dbContext;
    }
    [HttpGet]
    public async Task<IEnumerable<Item>> GetAsync()
    {
        List<Item> currentItems = new List<Item>();
        currentItems = await _dbContext.Item.ToListAsync();


        //this DOES in fact return my 1 row I have in the DB
        return currentItems;
    }
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseCors(policy =>
        {
            policy.WithOrigins("https://localhost:44356")
                  .AllowAnyMethod();
        });

        app.UseHttpsRedirection();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }