我在下面的文本框中我View
:ASP.NET MVC TextBoxFor佔位
的佔位符代碼:
@Html.TextBoxFor(m => m.Listing.Location.AddressLine1, new {@placeholder="Address Line 1 - Required"})
問題:如何讓文字RED中的「必需」。
我在下面的文本框中我View
:ASP.NET MVC TextBoxFor佔位
的佔位符代碼:
@Html.TextBoxFor(m => m.Listing.Location.AddressLine1, new {@placeholder="Address Line 1 - Required"})
問題:如何讓文字RED中的「必需」。
你不能用文本字段來做到這一點。您無法控制HTML5 placeholder
屬性的某些部分的格式。更何況,如果你想實現多色文本,你不能再使用文本字段或textarea。您將必須使用具有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" })
你需要爲它創建所需的模型實體和使用.. – Umitk