【发布时间】:2011-10-26 11:50:42
【问题描述】:
我有一个视图,它使用 TextBoxFor 辅助方法来编辑模型。像这样:
<div class="editor-field">
<%:Html.TextBoxFor(model => model.Property, new { @class = "mybox" })%>
<%: Html.ValidationMessageFor(model => model.Property)%>
</div>
所以,Modelbinder 工作正常,我可以编辑和保存我的模型。
当我像这样添加 html5 属性“类型”和“步骤”时
<div class="editor-field">
<%:Html.TextBoxFor(model => model.Property, new { @class = "mybox",@type = "number", @step = "1" })%>
<%: Html.ValidationMessageFor(model => model.Property)%>
</div>
我看到漂亮的数字控件而不是文本框,但是模型绑定会刹车,每当我更改我的属性时,我都会在我的模型中收到 0。提交时的属性。
我的代码有什么问题?
这是我的简单模型
public class Model
{
[DisplayName("Property")]
public int Property
{
get;
set;
}
}
内森,我对这个问题的解释在这里并不准确。这里Ajax Form breaks after adding html5 attributes in Chrome/Safari 是更好的描述和解决方法。
【问题讨论】:
标签: asp.net-mvc-2 html model-binding