現在、ASP.NET MVC 3 プロジェクトに取り組んでいます。パーセンテージを表示するカスタム エディター テンプレートを作成しました。ここに私がこれまでに持っているコードがあります。
public class MyClass
{
// The datatype can be decimal or double
[Percentage]
public double MyPercentage { get; set; }
}
[Percentage] 属性は、次のコードを使用する通常の UI ヒント属性です。
@model Object
@{
string fieldName = ViewData.TemplateInfo.HtmlFieldPrefix;
}
<div style="height: 24px;">
<div style="float: left;">
@Html.TextBox("", String.Format("{0:0.00}", Model), new
{
id = "txt" + fieldName,
@Class = "magnaNumericTextBox",
type = "magnaNumericType",
style = "width:230px"
})
%
</div>
<div style="float: left;">
<ul style="height: 24px; list-style: none; padding: 0px; margin: 0px; line-height: none;">
<li style="line-height: normal"><a id="btn@(fieldName)Up" class="magnaNumericButton button small">
˄</a> </li>
<li style="line-height: normal"><a id="btn@(fieldName)Down" class="magnaNumericButton button small">
˅</a> </li>
</ul>
</div>
</div>
<script type="text/javascript">
$("#btn@(fieldName)Up").click(function ()
{
ChangeNumericUpDownValue($('#txt@(fieldName)'), 1);
return false;
});
$("#btn@(fieldName)Down").click(function ()
{
ChangeNumericUpDownValue($('#txt@(fieldName)'), -1);
return false;
});
$('#txt@(fieldName)').keypress(function (e)
{
NumericUpDownKeyPress($(this), e);
return false;
});
</script>
このエディタ テンプレートは、ユーザーが必要に応じて使用できる数値アップ ダウン ローラーを使用します。ユーザーは、数値のアップダウン機能を使用せずに、自分で数値を入力することもできます。JavaScript の機能とすべてが、昨日までしばらくは完全に機能していました。
問題は、エディター テンプレートのテキスト ボックスで、ユーザーが自分の値を入力できず (読み取り専用にする - レンダリングされた html に読み取り専用属性はありません)、数値の上下ボタンを使用することだけです。次のように、テキスト ボックス ヘルパーから html 属性を削除すると、次のようになります。
@Html.TextBox("", String.Format("{0:0.00}", Model))
ユーザーがテキストボックスに値を入力して、もう一度値を追加できること。これは何が可能でしょうか?ヘルプやアドバイスをいただければ幸いです。
ありがとう