我在表单中使用 ASP.NET MVC 3 TextBoxFor,并且想使用 type="email"以便至少在某些移动设备上更轻松地输入,但找不到如何使用 TextBoxFor 进行设置。这不容易吗?
在 View 中
@Html.LabelFor(m => m.Email)
@Html.TextBoxFor(m => m.Email)
在模型中
[StringLength(50)]
public string Email { get; set; }
(已经使用数据注释来保护数据库中的大小约束)
最佳答案
尝试使用
@Html.TextBoxFor(m => m.Email, new { @type = "email" })
http://msdn.microsoft.com/en-us/library/ee703538.aspx (html属性)
关于asp.net-mvc-3 - 是否可以设置 TextBoxFor 生成的输入类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12267108/