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 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)



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