ASP.NET MVC框架中包含了一些预定义的HTML helper,可以起到简化输出HTML标记的效果,例如,其中的Html.TextBox helper方法就有以下4个重载形式:
string TextBox(... string name);
string TextBox(... string name, object value);
string TextBox(... string name, object value, IDictionary htmlAttributes);
string TextBox(... string name, object value, object htmlAttributes);
不过,虽说文本输入框是个相当简单的控件,但是上面4个重载形式也无法完全为您提供所有的选择,譬如格式化字符串的形式(像String.Format中那样)。您也可以编写更多的helper来实现希望的功能,但会弄乱Html helper的名字空间。
您或许会这样实现:
<%= Html.TextBox("ReleaseDate", String.Format("{0:d}", Model.ReleaseDate), new { @class = "special" })%>
或者,您也可以利用ASP.NET MVC futures中的新控件特性,这样实现:
ASP.NET MVC futures中还有许多类似的控件可供使用。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/740297/viewspace-586940/
,如需转载,请注明出处,否则将追究法律责任。