簡體   English   中英

VB.Net中具有Razor視圖的ASP.NET MVC 3上的HtmlAttributes

[英]HtmlAttributes on ASP.NET MVC 3 with Razor view in VB.Net

誰能告訴我如何在MVC 3 Razor視圖上添加此htmlAttribute?

New With {.watermark = "sometext", .title = "sometext"}

我嘗試了C#方式,但是它不起作用(@watermark),但是它不起作用。

謝謝。

UPDATE這里是我正在嘗試的當前用法,但無法正常工作。

  @Html.EditorFor(Function(model) model.FirstName, New With {.maxlength = "50"})

這也不起作用

 @Html.EditorFor(Function(model) model.FirstName, New Object() {"maxlength=50"})

請記住,我正在vb.net上執行此操作。 請幫助!

剛在互聯網上越過這個問題的答案,就自己跳了起來。 我正在使用的網站尚未發布,但是到目前為止,該解決方案對我來說是有效的。 這是我編寫並為我工作的確切代碼行:

@Html.CheckBox("chb", item.isAuditor, New With {.disabled = "disabled",  .tabIndex = "3"})

這段代碼位於處理每個“項目”的每個循環中,是控制器傳遞給視圖的列表。

讓我知道這是否適合您。

我有同樣的問題。 我本來就是這樣寫代碼的

@Html.DropDownListFor(Function(model) model.CostCentreID, ViewData("ListOfCostCentres"), New With {.size = "20"})

但這不起作用。 但是下面的方式有效,我想是因為我們需要先轉換ViewData才能使用它。

@Html.DropDownListFor(Function(model) model.CostCentreID, CType(ViewData("ListOfCostCentres"), SelectList), New With {.size = "20"})

以下為我工作:

@Html.TextBox("TextBoxName", New With {.maxlength = 3})

貝斯尼克,

要將vbhtml中的屬性添加到標記中,請使用以下示例:

@Html.TextBoxFor(Function(model) model.FirstName, New Object() { "title" = "sometext", "watermark" = "sometext")

counsellorben

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM