How to fill link the column in FormEdit and Edit action?

sblb 1,166 Reputation points
2022-09-24T09:10:34.817+00:00

Hi,
My app : blazor wasm aps.net core5.

First of all I tried, I will try to explain the configuration of my application is : DataGridView with several column of which ECR & ECO

244526-capture.png

The column ECR is fill when the user click on AddEcr. Thanks to @AgaveJoe the number is incremented with the current year. it's ok.
We can acces to ECO column when we click on Edit button. I want that the user can take or not the number ECO xxx/YY (with the same format that ECR).

The button Update correspond to the Edit.razor this means populate all data in table from database.

Edit.razor

 <FormEdit ButtonText="Update" dev="dev"  
       OnValidSubmit="@EditDeveloper" />  
      
 @code {  
      
     [Parameter] public int developerId { get; set; }  
     Developer dev = new Developer();  
      
      
     protected async override Task OnParametersSetAsync()  
     {  
         dev = await http.GetFromJsonAsync<Developer>($"api/developer/{developerId}");  
     }  
      
     async Task EditDeveloper()  
     {  
         await http.PutAsJsonAsync("api/developer", dev);  
         await js.InvokeVoidAsync("alert", $"Updated Successfully!");  
         uriHelper.NavigateTo("developer");  
                             
     }  

Now the button Number ECO allows to user take the number .

The definition of the button Number ECO is in FormEdit.razor

 <EditForm Model="@dev" OnValidSubmit="@OnValidSubmit">  
     <DataAnnotationsValidator />  
      
      
  <button type="submit" @onclick="@OnSubmitEcoNumber" >Submit</button>  
      
 </EditForm>  
      
 @code {  
  [Parameter] public Developer dev { get; set; }  
  [Parameter] public EventCallback OnValidSubmit { get; set; }  
          
     Developer[] developers { get; set; }   
 protected void OnSubmitEcoNumber()  
 {  
   //It's here that I've to call the method   
 }  
   }  

My question is : how to do the link between the button Number ECO (I think I have to put check box) with the Edit.razor to fill the column ECO?

the api is define below to fill the ECO number with a good format

  [HttpPost]  
        public async Task<IActionResult> Post(Developer developer)  
        {  
            YearCountECO deveco = await IncrementECODeveloperIdAsync();  
  
            developer.YearECO = deveco.YearECO;  
            developer.CountECO = deveco.CountECO;  
  
            YearCount dev = await IncrementDeveloperIdAsync();  
  
            developer.Year = dev.Year;  
            developer.Count = dev.Count;  
  
            _context.Add(developer);  
            await _context.SaveChangesAsync();  
            return Ok(developer.Id);  
        }        
    
  
 private async Task<YearCountECO> IncrementECODeveloperIdAsync()  
        {  
            if (!await _context.Developers.AnyAsync(d => d.Year == DateTime.Now.Year))  
            {  
                return new YearCountECO() { CountECO = 1, YearECO= DateTime.Now.Year };  
            }  
  
            int max = await _context.Developers.Where(d => d.Year == DateTime.Now.Year).MaxAsync(d => d.Count) + 1;  
            return new YearCountECO() { CountECO = max, YearECO = DateTime.Now.Year };  
        }  
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,398 questions
{count} votes

11 answers

Sort by: Most helpful
  1. sblb 1,166 Reputation points
    2022-09-28T10:15:53.983+00:00

    Hi, I tried to put checkbox w/o success!!

    FormEdit.razor

    <EditForm Model="@dev" OnValidSubmit="@OnValidSubmit">  
          <DataAnnotationsValidator />  
              
              
       <RadzenCheckBox @bind-Value=@checkBox1Value Name="CheckBox1" TValue="bool"  />  
              
      </EditForm>  
              
      @code {  
       [Parameter] public Developer dev { get; set; }  
       [Parameter] public EventCallback OnValidSubmit { get; set; }  
    
       bool checkBox1Value;  
                  
       Developer[] developers { get; set; }   
    
      protected void OnSubmitEcoNumber()  
      {  
         if (checkBox1Value==true)  
        {  
            dev.ECOSelected = true;  
        }   
      }  
        }  
    

    Edit.razor

    <FormEdit ButtonText="Update" dev="dev"  
            OnValidSubmit="@EditDeveloper" />  
              
      @code {  
              
          [Parameter] public int developerId { get; set; }  
          [Parameter] public int id { get; set; }  
          Developer dev = new Developer();  
              
              
          protected async override Task OnParametersSetAsync()  
          {  
              dev = await http.GetFromJsonAsync<Developer>($"api/developer/{developerId}");  
    
              if (dev.ECOSelected == true)  
              {  
                dev = await http.GetFromJsonAsync<Developer>($"api/developer/SelectEcoById/{id}");  
              }  
          }  
              
          async Task EditDeveloper()  
          {  
              await http.PutAsJsonAsync("api/developer", dev);  
              await js.InvokeVoidAsync("alert", $"Updated Successfully!");  
              uriHelper.NavigateTo("developer");  
                                     
          }