English 中文(简体)
MAUI Blazor的显示清单 json deserialization
原标题:Display List in MAUI Blazor App after json deserialization
  • 时间:2024-02-19 15:26:47
  •  标签:
  • blazor
  • maui

Display List in MAUI Blazor App after json deserialization, List is not displayed in MAUI Blazor App while the jsonString is displayed. The webapi is returning value when I deserialize to list it is giving error also cannot debug the code.Please suggest on this. I checked the List and json have same schema. https://github.com/KalyanAllam/RateApp/

@page "/"
@using System.Text;
@using System.Net.Http.Headers;
@using Microsoft.AspNetCore.Components;
@using Newtonsoft.Json;

@using RateApp.Models;

@jsonString


@Questions

<table class="table">
    <thead>
        <tr>
           
            <th>DaysBegin</th>
            <th>DaysEnd</th>
            <th>Interest</th>
            <th>SrInterest</th>
        </tr>
    </thead>
<tbody>
@foreach (InQuestion inques in Questions)
{
    // Pass the Dto properties to the component
    <InQuestion  DaysBegin="@inques.DaysBegin" DaysEnd="@inques.DaysEnd"   Interest="@inques.Interest"   SrInterest="@inques.SrInterest"/>
}
</tbody>
</table>

@code {
     public class InQuestion
    {




        public int No { get; set; }

        public int DaysBegin { get; set; }

        public int DaysEnd { get; set; }

        public decimal Interest { get; set; }

        public decimal SrInterest { get; set; }

    }
     



    public string codex; public string  jsonString ; public bool statcode;
     List<InQuestion> Questions = new List<InQuestion>();
     public int number; int totalquestions;
     protected override async Task OnInitializedAsync()
    {



        string jwturl = "https://quizapijwt.azurewebsites.net/api/";



        using (var client1 = new HttpClient())
        {
            

              
                client1.BaseAddress = new Uri(jwturl);

                client1.DefaultRequestHeaders.Clear();
                client1.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                 HttpResponseMessage response = await client1.GetAsync("RateCards");
             
                if (response.IsSuccessStatusCode)
                {
                    //Storing the response details recieved from web api
                      jsonString = await response.Content.ReadAsStringAsync();
                     
                       
                       
                       Questions = JsonConvert.DeserializeObject<List<InQuestion>>(jsonString);



                }
            }
            

   
   
        
    }
  }

问题回答

这是因为@ questionss。 你们想要

MAUI Blazor的显示清单 json deserialization

您可删除@ questionss@jsonstring,并在表格中显示数据。 例如:

<table class="table">
    <thead>
        <tr>
           
            <th>DaysBegin</th>
            <th>DaysEnd</th>
            <th>Interest</th>
            <th>SrInterest</th>
        </tr>
    </thead>
<tbody>
@foreach (InQuestion inques in Questions)
{
    // Pass the Dto properties to the component
            <tr>
                <td>@inques.DaysBegin</td>
                <td>@inques.DaysEnd</td>
                <td>@inques.Interest</td>
                <td>@inques.SrInterest</td>
            </tr>
        }
</tbody>
</table>

结果形象:

“entergraph





相关问题
Unable to access file in ResourcesSounds folder

I m using .net Maui and attempting to create audioManager players for a couple of sound files located in the ResourcesSounds folder in the project. The code is this: var playerStartSound = ...

.NET MAUI native audio player

I am interested is there a way to play mp3 files from the phone internal memory using the built in native audio player. I am asking this, because I want to implement an equalizer too, so I am guessing ...

Integrating Push Notifications in MAUI .NET 7 Applications

I m developing a cross-platform application using MAUI .NET 7 and I would like to add push notification functionality to my application. I m considering using Firebase Cloud Messaging or Azure ...

Databinding doesnt work in my xaml.cs file

I am trying to load some data from my Model to the xaml.cs file. But it doesn t work. In my Mainpage.xaml i have a binding property inside a label. In the code behind file a BindingContext to my ...

Do some tasks after OnAppearing() in MAUI

I have a maui community toolkit expander control in my page. On Tapping the header the content is shown/hidden .I got a Maui map in the expander s content. It display properly if the expander is in ...

NET MAUI是否有可调整的分辨率特征?

页: 1 NET MAUI用于一个即将到来的项目,但我发现一件失踪的事情是,我需要的是分裂的特征。 我发现,散射器在移动上可能不会产生作用,但Im主要针对Windows......。

How to optimize detail page reset button in C# MAUI?

I ve implemented a Reset button on a Detail page in C# MAUI and it works, but I can t figure out why I need to be so explicit in the way I capture the initial data to perform the reset, when requested....

热门标签