我有以下文本框View
:
占位符的代码:
@Html.TextBoxFor(m => m.Listing.Location.AddressLine1, new {@placeholder="Address Line 1 - Required"})
问题:如何在 RED 中显示“必填”文本。
我有以下文本框View
:
占位符的代码:
@Html.TextBoxFor(m => m.Listing.Location.AddressLine1, new {@placeholder="Address Line 1 - Required"})
问题:如何在 RED 中显示“必填”文本。
您不能使用文本字段执行此操作。您无法控制 HTML5placeholder
属性的某些部分的格式。更不用说,如果你想实现多色文本,你不能再使用文本字段或文本区域。您将不得不使用具有contenteditable="true"
属性的元素并编写您的自定义插件。
例如,标记的外观如下:
<div contenteditable="true">
Address Line 1 - <span style="color: red">Required</span>;
</div>
但由于这是一个div
元素,您现在必须使用相应的隐藏字段对其进行备份,以便将值发送到服务器。此外,当此字段的值更改时,您还需要重新同步隐藏字段值。这将是很多工作。
在模型中
[必需的]
public string AddressLine1{ get; set; }
@Html.TextBoxFor(model => model.Listing.Location.AddressLine1, new { @class = "form-control" , placeholder = "Address Line 1 - Required" })
试试这个空的@Html.TextBox
@Html.TextBox("CustomarName" ,null, new { @class = "form-control" , @placeholder = "Search With Customar Name" })