Solved

Removing Leading Zero in the MVC project

Posted on 2016-09-09
7
62 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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