简体   繁体   English

VB.Net中具有Razor视图的ASP.NET MVC 3上的HtmlAttributes

[英]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? 谁能告诉我如何在MVC 3 Razor视图上添加此htmlAttribute?

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

I tried the C# way but it's not working (@watermark) but it's not working. 我尝试了C#方式,但是它不起作用(@watermark),但是它不起作用。

Thanks. 谢谢。

UPDATE here is the current usage I am trying but it's not working. UPDATE这里是我正在尝试的当前用法,但无法正常工作。

  @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. 请记住,我正在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. 但是下面的方式有效,我想是因为我们需要先转换ViewData才能使用它。

@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: 要将vbhtml中的属性添加到标记中,请使用以下示例:

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

counsellorben counsellorben

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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