开发者

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 n开发者_StackOverflowot 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"})


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 following worked for me:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜