您可以通过定义一个新的字典来为 HTML 助手创建的 HTML 元素添加自定义属性,如下所示:
@Html.TextBox("q", Request("q"),
New Dictionary(Of String, Object) From
{
{ "data-autocomplete-source", Url.Action("QuickSearchTransactionNumber", "Home")},
{"class", "form-control"}, {"id", "TransactionNumber"},
{"placeholder", "Transaction Number"}
})
这将输出以下 HTML:
<input class="form-control" data-autocomplete-source="/Home/QuickSearchTransactionNumber" id="TransactionNumber" name="q" placeholder="Transaction Number" type="text" value="" />
此重载的文档:http: //msdn.microsoft.com/en-us/library/dd505258 (v=vs.108).aspx
如果你想LabelFor
在你的视图中使用 a (这是模型的强类型),你可以这样做:
@Html.LabelFor(Function(model) model.BranchNumber, New With { .class = "sr-only" })
您还必须使用Display
如下属性注释数据模型:
Imports System.ComponentModel.DataAnnotations
Public Class Bank
Private _branchNumber As String
<Display(Name:="Branch Number")>
Public Property BranchNumber() As String
Get
Return _branchNumber
End Get
Set(ByVal value As String)
_branchNumber = value
End Set
End Property
End Class