Solved

Removing Leading Zero in the MVC project

Posted on 2016-09-09
7
32 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 62

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 62

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 62

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.Net application crashing 6 21
JavaScript error 1 34
Hide Tab Page 3 20
Events in static methods 3 31
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now