下面的两行代码运行得很好,但我想将它们组合起来。我的意思是:我想在第一行代码中使用@class。我该怎么做呢?
<%: Html.TextBoxFor(model => model.Product.Price, String.Format("{0:f}", Model.Product.Price))%>
<%: Html.TextBoxFor(model => model.Product.Name, new { @class = "textBox150" })%>谢谢,
菲利普
发布于 2011-04-13 06:58:10
我知道我来晚了,但我刚刚找到了解决这个问题的办法:
<%: Html.TextBoxFor(model => model.StartDate, new { @class = "datepicker", Value=String.Format("{0:d}", Model.StartDate) })%>发布于 2011-01-23 17:09:56
我恐怕没有干净的方法来实现这一点。有几种可能性:
<%:Html.EditorFor(x => x.Product) %>
在这个编辑器模板中:
<%:Html.TextBox("Price",String.Format("{0:f}",Model.Product.Price),new { @class = "textBox150“})%> <%:Html.TextBoxFor(model => model.Product.Name,new { @class = "textBox150”}) %>
span中包装那些文本框<%:Html.TextBoxFor(model => model.Product.Price,string.Format("{0:f}",Model.Product.Price))%> <%:Html.TextBoxFor(model => model.Product.Name)%>然后修改CSS规则:
.container150 input { //一些适用于文本框的规则}
发布于 2012-08-23 19:22:41
再说一次,这可能太晚了,但我相信更好的解决方案是使用jquery.maskedinput插件(也可以使用nuget包)。
为什么使用插件比只使用输入格式更好?当有人修改输入时,如果你不使用插件,你就会失去格式化。
Here你可以找到它的用法和如何工作的演示。
https://stackoverflow.com/questions/4769267
复制相似问题