Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot get data from response when using HttpClient.GetJsonAsync in AspNetCore MVC #8540

Open
qwertylb opened this Issue Mar 15, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@qwertylb
Copy link

qwertylb commented Mar 15, 2019

When using HttpClient.GetJsonAsync, docList can't get Json data with Object List<Doc>. I set breakpoint in LogsController.cs, it's obvious that ActionResult already has Value. But docList is null. The following code snippet is a part of the webapplication.
How to get data and use it?
Thank you for your support...

QueryLogs.cshtml

<TextEdit Placeholder="PlayerGuid" bind-text="@account" />

<SimpleButton Clicked="@(async () => await GetLogs(account))" Class="form-control" Color="Color.Primary">
    Query
</SimpleButton>

<table>
    @if (docList == null)
    { <p>there are no doc to display</p>}
    else
    {
    @foreach (var doc in docList)
    {
        <tbody>
            <tr>
                <td>@doc.account</td>
                <td>@doc.money_after</td>
                <td>@doc.money_before</td>
                <td>@doc.operator_type</td>
                <td>@doc.item_info</td>
                <td>@doc.vipLevel</td>
                <td>@doc.quest_id</td>
                <td>@doc.weapon_id</td>
                <td>@doc.zone_id</td>
                <td>@doc.role_id</td>
            </tr>
        </tbody>}}

</table>


@functions{

    List<Doc> docList = new List<Doc>();
    string account;
    string document;

    public async Task GetLogs(string acc)
    {
        docList = await Http.GetJsonAsync<List<Doc>>("api/value/" + acc);
    }
}

LogsController.cs

[HttpGet("{param}")]
[EnableCors("CorsPolicy")]
private readonly ElasticClient _client;
public async Task<ActionResult<List<Doc>>> Search(string param)
{
    return  _client.Search<Doc>(s => s
        .From(0)
        .Size(10)
        .Query(q => q.Match(m => m.Field(f => f.account).Query(param)))).Documents.ToList<Doc>();     
}

@Eilon Eilon added the area-mvc label Mar 15, 2019

@mkArtakMSFT

This comment has been minimized.

Copy link
Member

mkArtakMSFT commented Mar 20, 2019

Thanks for contacting us, @qwertylb.
It's not clear from your example what you're experiencing. Are you getting an error? What is it?

@qwertylb

This comment has been minimized.

Copy link
Author

qwertylb commented Mar 21, 2019

Thanks for contacting us, @qwertylb.
It's not clear from your example what you're experiencing. Are you getting an error? What is it?

There is a project that use ASP.NET MVC and elasticsearch to query logs and represent it. In QueryLogs.cshtml, when i input account and click Query button, it will execute GetLogs method and it can get return value of account from LogsController's method Search. But the return value can not pass to the QueryLogs.cshtml by Http.GetJsonAsync<List>("api/value/" + acc). docList is null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.