HTML5 似乎支持新范围的 input fields对于 things such as :
- 数字
- 电子邮件地址
- 颜色
- 网址
- 数字范围(通过 slider )
- 日期
- 搜索框
是否有人为生成这些的 ASP.NET MVC 实现了 HtmlHelper
扩展方法?可以使用接受 htmlAttributes
的重载来执行此操作,例如:
Html.TextBoxFor(model => model.Foo, new { type="number", min="0", max="100" })
但这不如以下那样好(或类型安全):
Html.NumericInputFor(model => model.Foo, min:0, max:100)
最佳答案
请注意,其中许多现在已通过使用 DataType
合并到 MVC4 中。属性。
截至this work item你可以使用:
public class MyModel
{
// Becomes <input type="number" ... >
public int ID { get; set; }
// Becomes <input type="url" ... >
[DataType(DataType.Url)]
public string WebSite { get; set; }
// Becomes <input type="email" ... >
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
// Becomes <input type="tel" ... >
[DataType(DataType.PhoneNumber)]
public string PhoneNumber { get; set; }
// Becomes <input type="datetime" ... >
[DataType(DataType.DateTime)]
public DateTime DateTime { get; set; }
// Becomes <input type="date" ... >
[DataType(DataType.Date)]
public DateTime Date { get; set; }
// Becomes <input type="time" ... >
[DataType(DataType.Time)]
public DateTime Time { get; set; }
}
关于.net - 用于新 HTML5 输入类型的 ASP.NET MVC HTML 帮助器方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3613060/