我目前正在开发ASP.NET MVC 3项目。我制作了一个自定义编辑器模板来显示百分比。这是我迄今为止的代码。Html属性中断编辑器模板,使其只读
public class MyClass
{
// The datatype can be decimal or double
[Percentage]
public double MyPercentage { get; set; }
}
的[百分比] attribue是一个正常的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="[email protected](fieldName)Up" class="magnaNumericButton button small">
˄</a> </li>
<li style="line-height: normal"><a id="[email protected](fieldName)Down" class="magnaNumericButton button small">
˅</a> </li>
</ul>
</div>
</div>
<script type="text/javascript">
$("#[email protected](fieldName)Up").click(function()
{
ChangeNumericUpDownValue($('#[email protected](fieldName)'), 1);
return false;
});
$("#[email protected](fieldName)Down").click(function()
{
ChangeNumericUpDownValue($('#[email protected](fieldName)'), -1);
return false;
});
$('#[email protected](fieldName)').keypress(function (e)
{
NumericUpDownKeyPress($(this), e);
return false;
});
</script>
该编辑模板利用一个数字上下辊的,使得用户可以,如果他使用/她喜欢。用户也可以自己输入数字,而不使用数字向上功能。 JavaScript功能和一切工作完美一段时间,直到昨天。
现在的问题是,编辑器模板中的文本框不允许用户键入他/她自己的值(使其只读 - 尽管呈现的html中没有只读属性),只能通过数字向上键入纽扣。我已经决定,如果我从文本框中助手删除HTML属性,像这样:
@Html.TextBox("", String.Format("{0:0.00}", Model))
用户可以再次通过键入到文本框中添加值。这可能是什么?任何帮助或建议,将不胜感激。
感谢
您为该字段生成ID的方式不正确。 'ViewData.TemplateInfo.HtmlFieldPrefix'是该字段的前缀(例如[Car.Window。< - HtmlPrefix] Color)。如果你想要一个Id或Name,你应该在模板 – 2012-03-07 13:47:29