Solved

Removing Leading Zero in the MVC project

Posted on 2016-09-09
7
46 Views
Last Modified: 2016-09-13
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!
0
Comment
Question by:eli411
  • 4
  • 3
7 Comments
 
LVL 63

Expert Comment

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

Open in new window

0
 
LVL 2

Author Comment

by:eli411
ID: 41791720
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
 
LVL 2

Author Comment

by:eli411
ID: 41791721
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 41791755
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
 
LVL 2

Author Comment

by:eli411
ID: 41791839
thank you Fernado!
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41792696
Hi eli411;

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

Thank you.
0
 
LVL 2

Author Closing Comment

by:eli411
ID: 41796870
The syntax works!  Thanks Fernando.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question