如何为 TextBoxFor 元素设置默认文本(在创建 View 中):
@Html.TextBoxFor(Function(model) model.QualityM1s, New With {Key .text="0"})
最佳答案
不太确定您所说的默认文本是什么意思。如果你想用一些值预初始化文本框,你可以使用普通文本框:
@Html.TextBoxFor(Function(model) model.QualityM1s)
然后您可以在将模型传递给 View 之前将相应的 View 模型属性设置为 Controller 操作中的默认值:
model.QualityM1s = "some default text"
return View(model)
然后 TextBoxFor 助手将使用您的模型属性的值来填充相应的文本框。
如果您想应用水印效果,您有两种可能性:
使用新的 HTML 5 placeholder attribute (这显然假设客户端浏览器支持它):
@Html.TextBoxFor(Function(model) model.QualityM1s, New With { Key .placeholder = "some default text"})
使用javascript。例如有 many jQuery watermark plugins .
关于asp.net - TextBoxFor 默认文本的 MVC asp.net VB 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10415758/