Html.TextBox助手用法

时间:2013-08-27 09:49:01

标签: asp.net-mvc vb.net razor

您好我正在尝试使用vb语法将以下HTML输入转换为razor html.textbox助手

<input type="text" name="q" data-autocomplete-source="@Url.Action("QuickSearchTransactionNumber", "Home")" class="form-control" id="TransactionNumber" placeholder="Transaction Number">

任何帮助都会很棒

1 个答案:

答案 0 :(得分:0)

您可以通过定义新字典来为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(强烈键入模型),您可以这样做:

@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