How do I format decimal as Percentage in EF Code First rendered in Razor TextBoxFor?

asp.net-mvc c# entity-framework razor

Accepted Answer

ZZZ_tmp
9
5/23/2017 12:34:22 PM

Popular Answer

Here is how I used one of the post's recommendations in the end.

public class JobCand
{
    [Key]
    [HiddenInput(DisplayValue = false)]
    public int JC_ID { get; set; }

    public int Job_ID { get; set; }

    public int Candidate_ID { get; set; }

    [DataType(DataType.MultilineText)]
    [StringLength(250)]
    public string JC_Note { get; set; }

    [DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:P0}")]
    [RegularExpression(@"[0-9]+(\.[0-9][0-9]?)?$", ErrorMessage = "Invalid rate")]
    public decimal? JC_Skill_Match_Pct { get; set; }

}

I'll tell you one thing: formatting in this way is considerably simpler than formatting using ASP.NET controls or C#.NET code. I like how MVC advises handling everything in the entity class. There were numerous accounting displays with $ and percent formatting necessary for the program I created for the Clark County Assessor's office. I had a lot of discomfort as a result of the work required to convert back and forth for display, editing, extraction, and database updates. Not to mention that I was also using update panels.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow