Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

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

C#
[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

1 solution

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
C#
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) })
 
Share this answer
 
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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900