message error CS1525

sblb 1,231 Reputation points
2022-08-03T16:10:18.813+00:00

Hi,

I would like to put a specific value in table when I click on add bouton

class model

public partial class Developer  
{  
        public int Id { get; set; }  
        public string ECR { get; set; }  
        public DateTime DateCrea { get; set; }  
       
 }  

razor page
<div class="col-md-6">
<RadzenTextBox style="width: 100%;" Name="Numéro ECR" @bind-Value=IncrementECR() >
</RadzenTextBox>
<ValidationMessage For="@(() => dev.ECR)" />
</div>

@code {  
    [Parameter] public Developer dev { get; set; }  
  
    private readonly int _currentYear = DateTime.Today.Year;      
  
    public void IncrementECR()  
    {  
        int datecrea = dev.DateCrea.Year;  
  
        if(datecrea == _currentYear)  
        {  
           @dev.ECR = 001 + "/" + _currentYear;                        
             
        }     
    }  
}  

I received the message that I don't understand : the invalid '=' expression term
because I want to assign a value to @dev.ECR and not compare with '=='

FYI, I used the several source to create my application, I list below the different links
blazor-crud-with-entity-framework-core
blazor-api-handling
dashboard

Developer technologies | .NET | Blazor
0 comments No comments
{count} votes

9 answers

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2022-08-03T19:24:59.063+00:00

    The C# syntax is...

    dev.ECR = "001" + "/" + _currentYear.ToString();   
    

    The @ is used in Razor markup to transistion between C# and HTML. The @ is used in C# to define a literal string or use a verbatim identifier.

    I would use string interpolation though.

    dev.ECR = $"001/{_currentYear}";  
    

    Please see the C# programming guide.

    String interpolation in C#
    @ (C# Reference)
    Razor syntax reference for ASP.NET Core

    Keep in mind, Radzen is a 3rd party framework. Radzen is a better support option for Radzen element questions.


  2. sblb 1,231 Reputation points
    2022-08-05T09:58:51.823+00:00

    Thanks to your reply. FYI, I use only the radzen library for my UI this means I don't use the radzen to build my application.

    I no longer have the CS1525 error but now I get the following message : 'FormCreate.IncrementECR()' : not all paths in the code return a value; why?

      <div class="col-md-6">  
                            <RadzenTextBox style="width: 100%;" Name="Numéro ECR" @bind-Value=@IncrementECR()>  
                            </RadzenTextBox>     
                            <ValidationMessage For="@(() => dev.ECR)" />  
                        </div>  
    
        @code{  
        private readonly int _currentYear = DateTime.Today.Year;      
      
        private string IncrementECR()  
        {  
            int datecrea = dev.DateCrea.Year;  
      
            if(datecrea == _currentYear)  
            {  
                 
                return dev.ECR= $"001/{_currentYear}";  
            }         
        }  
        }  
    
       
    
    0 comments No comments

  3. Anonymous
    2022-08-05T11:09:11.027+00:00

    I no longer have the CS1525 error but now I get the following message : 'FormCreate.IncrementECR()' : not all paths in the code return a value; why?

    Your original question has been answered. It is customary to mark the post as answered and ask a new question.

    Unfortunately we have no idea what you are thinking. What do want to return when datacrea does not equal _currentYear?

    Something like this?

     private string IncrementECR()  
     {  
         int datecrea = dev.DateCrea.Year;  
      
         if(datecrea == _currentYear)  
         {      
             return dev.ECR= $"001/{_currentYear}";  
         }       
         return return dev.ECR;  
     }  
    

    Anyway, I would rethink the design and place this logic in the Developer class.

    0 comments No comments

  4. sblb 1,231 Reputation points
    2022-08-05T13:40:12.467+00:00

    as I said in my first post I would like to put a specific value in a cell of the ECR column when I click on the Add ECR button.
    228544-capture.png

    The structure of my application is as follow :

    Fetch.razor where there is a button Add ECR

    <div class="form-group">  
        <a class="btn btn-primary" href="developer/create">Add ECR</a>  
    </div>  
    

    developer/create

    @page "/developer/create"  
    @inject HttpClient http  
      
    @inject NavigationManager uriHelper  
      
    <FormCreate ButtonText="Create Developer" dev="@dev"  
                OnValidSubmit="@CreateDeveloper"/>  
      
    @code {  
        Developer dev = new Developer();  
      
        async Task CreateDeveloper()  
        {  
            await http.PostAsJsonAsync("api/developer", dev);  
            uriHelper.NavigateTo("developer");  
        }  
      
    }  
    

    FormCreate.razor

    <EditForm Model="@dev" OnValidSubmit="@OnValidSubmit">  
        <DataAnnotationsValidator />  
      
      <RadzenFieldset Text="Creation ECR">  
                    <div class="row">  
                        <div class="col-md-4 align-items-center d-flex">  
                            <RadzenLabel Text="Numéro ECR" />  
                        </div>  
                        <div class="col-md-6">  
                            <RadzenTextBox style="width: 100%;" Name="Numéro ECR" @bind-Value=@IncrementECR()>  
                            </RadzenTextBox>     
                            <ValidationMessage For="@(() => dev.ECR)" />  
                        </div>  
                    </div>  
    ...  
         </RadzenFieldset>  
    </EditForm>  
    

    when I click on Add ECR I would like to fill the TexBox with the specifier value eg 001/22. Each time I click on Add ECR this value is incremented 001/22; 002/22; ...100/22...
    When the year change (eg 2023) I want to initialize the value at 001/23...

    228545-capture.png


  5. sblb 1,231 Reputation points
    2022-08-05T20:25:10.177+00:00

    why you would put the number in a text input.

    I want to put a specific value which takes a form "001/22" which will be a string value.

    The code to add number increment

           private readonly int _currentYear = DateTime.Today.Year;      
           int counter = 0;  
          private string IncrementECR()  
          {              
                 dev.ECR = counter.ToString("00") + "/" + _currentYear.ToString();  
               counter++;  
    
                return dev.ECR ;  
                
          }  
    

    But there are always the message cs1525


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.