How to assign a variable to a modal validation Error Message

*******  THIS IS MY ACTUAL MODAL ********

[Required(ErrorMessage = "Please enter Login Name")]
public string Login_Name { get; set; }



******** I WANT TO ACHIVE LIKE *********

public static string errormessage = "my custom error messaage";
[Required(ErrorMessage = errormessage)]
public string Login_Name { get; set; }


But i am getting an error :  An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

i am new to Blazor so please help me with a better and easy solution


Thanks In Advance


1 Reply 1 reply marked as answer

SP Sureshkumar P Syncfusion Team March 23, 2022 05:46 AM UTC

Hi Suryateja, 
 
Edit form validation error message required constant string message to return validation message. So, we suggest you change the validation error message as constant string as like below to achieve your requirement.

 
Find the code example here: 
 
@using Syncfusion.Blazor.Inputs 
@using System.ComponentModel.DataAnnotations 
@using Syncfusion.Blazor.Buttons 
 
<EditForm Model="@model"> 
    <DataAnnotationsValidator /> 
    <SfTextBox @bind-Value="@model.TextName" Placeholder="enter name" FloatLabelType="FloatLabelType.Auto"></SfTextBox> 
    <ValidationMessage For="() => model.TextName" /> 
    <SfButton CssClass="e-small e-info" Content="Submit"></SfButton> 
</EditForm> 
 
@code { 
    public class CountriesModel 
    { 
        public const string errormessage = "my custom error messaage"; 
        [Required(ErrorMessage = errormessage)] 
        public string TextName { get; set; } 
    } 
    public CountriesModel model = new CountriesModel(); 
 } 
 
 
 
 
Regards, 
Sureshkumar P 


Marked as answer
Loader.
Up arrow icon