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!
LVL 2
eli411Asked:
Who is Participating?
 
Fernando SotoRetiredCommented:
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

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

Open in new window

0
 
eli411Author 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.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
eli411Author 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."}
0
 
eli411Author Commented:
thank you Fernado!
0
 
Fernando SotoRetiredCommented:
Hi eli411;

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

Thank you.
0
 
eli411Author Commented:
The syntax works!  Thanks Fernando.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.