简体   繁体   English

自定义非验证属性 ASP.NET 核心

[英]Custom nonvalidation attribute ASP.NET Core

I know how to create custom validation attribute using IClientModelValidator where I can add html attributes using ClientModelValidationContext , but how to create an attribute, like nonwritable that sets html class with disable to input;我知道如何使用 IClientModelValidator 创建自定义验证属性,我可以使用IClientModelValidator添加ClientModelValidationContext属性,但如何创建一个属性,例如设置nonwritable ZA2F2ED4F8EBC2CBB14C21A29DZ 的不可写属性到输入; it's not good to do it in validation context.在验证上下文中这样做并不好。

Sorry for my English对不起我的英语不好

<input type="text" id="ex" name="example" disabled>

When a disabled attribute is present, it specifies that the element should be disabled.当一个 disabled 属性存在时,它指定该元素应该被禁用。 A disabled input element is unusable as well as un-clickable.禁用的输入元素既不可用也不可点击。

The disabled attribute can be set to keep a user from using the element until some other condition has been met (like selecting a checkbox, etc.).可以设置 disabled 属性以阻止用户使用该元素,直到满足某些其他条件(例如选择复选框等)。 Then, a JavaScript could remove the disabled value, and make the element usable.然后,JavaScript 可以删除禁用的值,并使元素可用。

You can do it with easier with some tag helper or HTML helper that will render this depending on the condition you pass in.您可以使用一些标签助手或 HTML 助手更轻松地完成此操作,它们将根据您传入的条件进行渲染。

Example with HTML helper: HTML 助手的示例:
Conditionally render disabled button in asp.net core view 在 asp.net 核心视图中有条件地呈现禁用按钮
Example with tag helper:带有标签助手的示例:
Input Tag Helper Not Working with Razor Code 输入标签助手不适用于 Razor 代码

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

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