Asp.net-Mvc-3

是否可以設置 TextBoxFor 生成的輸入類型

  • September 4, 2012

我在表單中使用 ASP.NET MVC 3 TextBoxFor 並希望使用 type=“email” 以便至少在某些移動設備上更輕鬆地輸入,但找不到如何使用 TextBoxFor 進行設置。這不容易嗎?

在視圖中

@Html.LabelFor(m => m.Email)
@Html.TextBoxFor(m => m.Email)

在模型中

[StringLength(50)]
public string Email { get; set; }

(已經使用數據註釋來保護 DB 中的大小約束)

嘗試使用

@Html.TextBoxFor(m => m.Email, new { @type = "email" })

<http://msdn.microsoft.com/en-us/library/ee703538.aspx> (htmlAttributes)

引用自:https://stackoverflow.com/questions/12267108