简体   繁体   English

将自动完成属性添加到R​​azor中的文本框

[英]Adding AutoComplete attribute to textbox in Razor

In Razor I can turn off Autocomplete on a textbox by doing this: 在Razor中,我可以通过执行以下操作来关闭文本框上的“自动完成”功能:

@Html.EditorFor(model => model.UserName, new { autocomplete = "off" })

Is there a way I can specify this in the ViewModel using DataAnnotations instead of in the View? 有没有一种方法可以在DataModel中使用DataAnnotations而不是在View中指定?

I don't think there is a standard way to manipulate html attributes from ViewModel attributes with the EditorFor extension method. 我认为没有一种标准方法可以使用EditorFor扩展方法从ViewModel属性处理html属性。

However, you can create a custom html helper method if you want to keep it DRY. 但是,如果要保持DRY状态,则可以创建一个自定义html helper方法

Btw I don't think that it would be a great idea to encapsulate these kind of informations (html attributes) inside a ViewModel class. 顺便说一句,我认为将这些信息(html属性)封装在ViewModel类中不是一个好主意。

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

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