Removing Leading Zero in the MVC project

eli411
eli411 used Ask the Experts™
on
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!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fernando SotoRetired
Distinguished Expert 2017

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

Open in new window

Author

Commented:
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.

Author

Commented:
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."}
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Retired
Distinguished Expert 2017
Commented:
Sorry about that, this should work. In your model change
[DisplayName("Credit Score")]
public string fico222 { get; set; }

//To this

private string _fico222;

[DisplayName("Credit Score")]
public string fico222
{
	get { return _fico222.TrimStart('0'); }
	set { _fico222 = value; } 
}

Open in new window

Author

Commented:
thank you Fernado!
Fernando SotoRetired
Distinguished Expert 2017

Commented:
Hi eli411;

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

Thank you.

Author

Commented:
The syntax works!  Thanks Fernando.
its doesn't work for me

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial