Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC3
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 22: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
0 BillWoodruff 300
1 Mathew Soji 274
2 Afzaal Ahmad Zeeshan 268
3 DamithSL 225
4 Sergey Alexandrovich Kryukov 205
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2014
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