Avatar of eli411
eli411
 asked on

Removing Leading Zero in the MVC project

I have my code in the MVC project in the following.

Razor form code below ---------------------------------------------------------------------------------------------------------

@Html.DisplayFor(model => model.fico222)        Which displays fico score (String) Ex: 0790
-------------------------------------------------------------------------------------------------------------------------------------------


Model class code below---------------------------------------------------------------------------------------------------------
        [DisplayName("Credit Score")]
        public string fico222 { get; set; }

----------- I wanted the returning fico score return with 790 instead of 0790 so how can I change that in my syntax??  
Thank you!
ASP.NETC#.NET Programming

Avatar of undefined
Last Comment
divya jyothi

8/22/2022 - Mon
Fernando Soto

Try this line of code for yours.
@Html.DisplayFor(model => model.fico222.TrimStart('0'))

Open in new window

eli411

ASKER
Got following errors

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
eli411

ASKER
Here is the error from the Visual Studio

{"Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions."}
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Fernando Soto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
eli411

ASKER
thank you Fernado!
Fernando Soto

Hi eli411;

If my last post answered your question please mark it as the solution to the question.

Thank you.
eli411

ASKER
The syntax works!  Thanks Fernando.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
divya jyothi

its doesn't work for me