Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8985067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:15:16+00:00 2026-06-15T21:15:16+00:00

Suppose if I have an Annotation like the following [DisplayFormat(DataFormatString = {0:#.00#}, ApplyFormatInEditMode =

  • 0

Suppose if I have an Annotation like the following

[DisplayFormat(DataFormatString = "{0:#.00#}", ApplyFormatInEditMode = true)]

It works great. But suppose I want to replace the DataFormatString in real time i.e. some times like this {0:#.00#} and sometimes {0:#.000#} based on some application settings the user chooses. Is there a way to do that?

I tried storing the format string in a global variable, but it gives me the following error.

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

If I make the global variable constant it works but then the purpose is lost. Any advice on a work around?

Basically I would like to give the users an option to set the decimal spaces universally with out having to implement the feature on a per View/Controller basis.

I know I can put the culture using NumberFormat.CurrencyDecimalDigits. But this will ignore Zeros after the decimal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:15:17+00:00Added an answer on June 15, 2026 at 9:15 pm

    Attribute requires constant string, you can’t change that. Also this attribute does not provide ability to provide resource name. So, I think best way to you is creating DisplayTemplate and EditorTemplate for this property.

    [UIHint("Bar")]
    public decimal Bar { get; set; }
    

    And in Bar template you can change format based on some application settings chosen by user:

    @model decimal
    
    @Model.ToString(HttpContext.Current.Session["format"].ToString())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following XML (which is the embedding of TEI annotation scheme
Suppose I have this annotation @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Name { String value(); }
Suppose we have the name written in any none-latin letters - languages, like Arabic,
This question relates to Django Aggregation/Annotation in 1.1. Suppose I have a simple model
Suppose I have the following scala classes ( that needs to improve to address
Suppose I have this annotation class @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface MethodXY { public int
Suppose I have an interface and many classes implementing that interface. I want to
Suppose I have a module with the methods : function1,function2,function3. I want to import
suppose i have a jax-rs resource class that looks like this: @Path(/nodes) public class
Suppose I have a button that I am adding to an annotation object in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.