2011-02-04 5 views
2
  • ###、###、###、## 0.00" モデルで はので、私は100を入力した場合でも、それは自動的にMaxLenthのように、テキストボックスのためのMaxLengthを指定する方法$ 100.00formatStringの()

答えて

6

なるべき= "18"

あなたが渡すことができ、追加のHTMLはTextBoxForメソッドに属性:formatStringの= "$ ###、###、###などのTextBox書式文字列を設定する方法

<%= Html.TextBoxFor(x => x.SomeValue, new { maxlength = "18" }) 

:##にモデルで0.00" は、私は100を入力した場合でも、それは自動的にあなたが [DisplayFormat]属性を使用することができます$ 100.00

になるべき次いで

[DisplayFormat(DataFormatString = "{0:$###,###,###,##0.00}", ApplyFormatInEditMode = true)] 
public decimal? Value { get; set; } 

と:、ApplyFormatInEditMode = maxlength.But [displayFormatに(DataFormatString = "{$ ###、###、###、## 0.00 0}" の

<%= Html.EditorFor(x => x.Value) %> 
+0

おかげtrue)] public decimal?値{get;セット; }は動作していません。 –

+3

@Basavaraj、あなたは 'Html.TextBoxFor(x => x.Value)'の代わりにあなたのビューで 'Html.EditorFor(x => x.Value)'を使いましたか? 'DisplayFormat'属性は、' EditorFor'ヘルパーを使うときだけ適用されます。 –

関連する問題