0

これら 2 つの textboxfor があり、小数点以下 2 桁までしか入力できないようにする必要があります。私は、jQuery または Javascript イベントがこれを行うことができると仮定しています。Javascript で textboxfor を呼び出す方法がわかりません。どんな助けでもいただければ幸いです

@Html.TextBoxFor(m => Model.Categories[c].EstimateGroups[g].EstimateItems[i].PerUnitCost,
                 new { @disabled = "disabled", @onchange = "costUpdate(this);", @cstType = "perUnit",@id="perUnit"})

<span class="sideLabel">@Model.Categories[c].EstimateGroups[g].EstimateItems[i].PerUnitDescription</span>

if (Model.Categories[c].EstimateGroups[g].EstimateItems[i].Units != null
 && !Model.Categories[c].EstimateGroups[g].EstimateItems[i].IsBasedOnHomeSquareFootage)
{ 
    @Html.TextBoxFor(m => Model.Categories[c].EstimateGroups[g].EstimateItems[i].Units,
                     new { @disabled = "disabled", @onchange = "costUpdate(this);", @cstType = "units" })
}
4

1 に答える 1

2

RegularExpression属性を使用できます。これは仕事をします。

[RegularExpression(@"^\d+.\d{0,2}$", 
             ErrorMessage = "It cannot have more than one decimal point value")]
public double PerUnitCost {get;set;}   

ここで{0,2}、0 と 2 は小数点以下の最小桁数と最大桁数を意味します。したがって、要件に応じて変更してください。

于 2013-08-14T15:02:18.273 に答える