Click here to Skip to main content
12,954,601 members (56,899 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi Friends,

I have put it the following code for the initial investment
Model code

[DataType(DataType.Currency)]
[Required(ErrorMessage = "Initial investment is required")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:C}")]
[Display(Name = "Initial Investment")]
[RegularExpression("^[1-9]+[0-9]*$", ErrorMessage = "Initial investment is numeric")]
public string InitialInvestment { get; set; }


Aspx code

<%: Html.TextBoxFor(InitialInvestment => Model.InitialInvestment., new { @class = "textbox", style = "width:105px", maxlength = "15"})%>


but this is not displaying in currency format

Please help me to solve the issue

Thanks
Posted 5-Sep-12 21:54pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You have the wrong usage of Lambda Expressions in Textbox

Replace

<%: Html.TextBoxFor(InitialInvestment => Model.InitialInvestment., new { @class = "textbox", style = "width:105px", maxlength = "15"})%>


with

<%: Html.TextBoxFor(m=>m.InitialInvestment , new { @class = "textbox", style = "width:105px", maxlength = "15"})%>


Now try the above format, you should get it running.

OR

You even dont need to use annotations for that. Remove
DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:C}")]
and write the following

@Html.TextBoxFor(model => model.InitialInvestment, new { @class = "textbox", id = "InitialInvestment", Value=String.Format("{0:C}",Model.InitialInvestment) })
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,153
ppolymorphe 2,030
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100