Hello. I'm in the process of developing a blazor program. The page contains a drop down list, a button and a table. I need to select a client from the drop down list to retrieve the data for the client from the Database. But when I press the button, all clients come from the database in the table. I enclose the codes below. Is there anyone can help me with that?
@page "/Kontoplan" @using BOGF.Models @using Gateway <h1>Kontoplan</h1> <EditForm Model="@klient"> <div> <InputSelect @bind-Value="KlientId" name="KlientId" id="KlientId" class="form-control" style="width: auto; float: right"> <option selected disabled ="">-- Vælg en Klient --</option> @foreach (var klient in klienter) { <option id="@klient.Id" name="@klient.Name">@klient.Id- @klient.Name</option> } </InputSelect> <button type="submit" class="btn btn-primary" style="width:100px; float:right" @onclick="@OnInitializedKontoplan">Hent</button> </div> @if (kontoplans is null) { <div class="spinner"></div> } else { <table class="table table-striped"> <thead> <tr> <th style="width:110px">LåsKonto</th> <th>Kontonummer</th> <th>Navn</th> <th>Type</th> <th>Moms</th> <th>LockKonto</th> <th>KlientId</th> </tr> </thead> <tbody> @foreach (var kontoplan in kontoplans) { string lockkonto = kontoplan.LockKonto.ToString(); if (lockkonto == "Locked") { <tr style="background-color:skyblue"> <td><input type="checkbox" checked /></td> <td>@kontoplan.Kontonummer</td> <td>@kontoplan.Navn</td> <td>@kontoplan.Type</td> <td>@kontoplan.Moms</td> <td>@kontoplan.LockKonto</td> <td>@kontoplan.KlientId</td> </tr> } else { <tr> <td><input type="checkbox" /></td> <td>@kontoplan.Kontonummer</td> <td>@kontoplan.Navn</td> <td>@kontoplan.Type</td> <td>@kontoplan.Moms</td> <td>@kontoplan.LockKonto</td> <td>@kontoplan.KlientId</td> </tr> } } </tbody> </table> } </EditForm> @code { [Parameter] public int Id { get; set; } [Parameter] public int KlientId { get; set; } List<KontoplanModel> kontoplans = null; KlientGateway gateway = new KlientGateway(); List<KlientModel> klienter = new List<KlientModel>(); KlientModel klient = new KlientModel(); KontoplanModel kpm = new KontoplanModel(); protected override void OnInitialized() { klienter = gateway.GetAllKlient(); } protected void OnInitializedKontoplan() { kontoplans = gateway.GetKontoplan(KlientId); KlientId = kpm.KlientId; }
public class KlientGateway { ApplicationDbContext _db = new ApplicationDbContext(); public List<KlientModel>GetAllKlient() { return _db.Klient.ToList(); } public List<KontoplanModel> GetKontoplan(int KlientId) { return _db.Kontoplan.ToList(); } }
namespace BOGF.Models { [Keyless] public class KontoplanModel { public int Kontonummer { get; set; } public string Navn { get; set; } public string Type { get; set; } public string Moms { get; set; } public string LockKonto { get; set; } public int KlientId { get; set; } } }
public List<KontoplanModel> GetKontoplan(int KlientId) { return _db.Kontoplan.Where(x => x.KlientId == KlientId).ToList(); }
<option id="@klient.Id" name="@klient.Name" value="@klient.Id">@klient.Id - @klient.Name</option>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)