Click here to Skip to main content
11,716,083 members (87,767 online)
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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 683
1 Richard MacCutchan 280
2 Maciej Los 259
3 OriginalGriff 160
4 F-ES Sitecore 135
0 Sergey Alexandrovich Kryukov 1,003
1 Richard MacCutchan 430
2 CHill60 415
3 Maciej Los 399
4 OriginalGriff 385


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2015
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