We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Attribute translation Short name and prompt


I use the function C.T(word to translate) to do the translation of my app. I use the pot format and not ressource method so I can't use the ressourcename as attribute.

I have a model with this code and have an issue with the attributes:

  [Display(ShortName = C.T("Transaction password"), Prompt = C.T("Enter password"))]
        public string Password { get; set; }

I have the error: 

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

How can I fix this issue? What is the workarround?


1 Reply

SP Subburaj Pandian Veluchamy Syncfusion Team June 3, 2019 07:21 AM

Hi Alexis, 
Thank you for contacting Syncfusion support. 
We have analyzed the reported query “How to use an attribute with the method as parameter value?” attribute parameter should be a constant value since they are evaluated at compile time, your method value can change at runtime. 
You can achieve your requirement by using AutoGeneratingDataFormItemevent, in which you can set Labeltext and PlaceHolderText using custom methods to Translate. Please refer the following code, 
Code Snippet: 
private void DataForm_AutoGeneratingDataFormItem(object sender, AutoGeneratingDataFormItemEventArgs e) 
         if(e.DataFormItem != null) 
                if(e.DataFormItem.Name == "Password") 
                    e.DataFormItem.LabelText = Translate(e.DataFormItem.Name); 
                    e.DataFormItem.PlaceHolderText = Translate("Enter password"); 
Kindly refer the following KB for more information about changing placeholder text,  
We have prepared a sample for the same, 
Sample link: DataForm 
We hope this helps. Kindly revert us if you have any concern. 
Subburaj Pandian V 

Live Chat Icon For mobile
Up arrow icon