简体   繁体   中英

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

Can anybody tell me how do I add this htmlAttribute on MVC 3 Razor view?

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

I tried the C# way but it's not working (@watermark) but it's not working.

Thanks.

UPDATE here is the current usage I am trying but it's not working.

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

This isn't working either

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

Bear in mind that I am doing this on vb.net. PLEEASE HELP!

Just crossed all over the internet for the answer to this and tripped on the solution myself. Granted the site I'm working on isn't live yet, but so far this solution is working for me. Here is the exact line of code that I wrote and is working for me:

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

That piece of code is in a for each loop which is processing each "item" is the list passed to the view by the controller.

Let me know if that works for you.

I was having the same issue. i was originally writing the code like this

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

but this was not working. but the following way work, i guess because we need to typecast ViewData before we can use it.

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

以下为我工作:

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

Besnik,

To add attributes in vbhtml to your markup, use the following as an example:

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

counsellorben

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM