asp.net有条件地禁用标签助手(文本区域) [英] asp.net conditionally disable a tag helper (textarea)

查看:52
本文介绍了asp.net有条件地禁用标签助手(文本区域)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据模型评估的条件来启用或禁用textarea,并且我正在使用textarea标签帮助器. 换句话说,是这样的:

I want to enable or disable a textarea depending on a condition that evalueates from the model, and I am using the textarea tag helper. In other words, something like this:

<textarea asp-for="Doc" @(Model.MustDisable ? "disabled" : "")></textarea>

但是我遇到了以下设计时错误:标记助手'textarea'在元素的属性声明区域中不能包含C#.

But I got the following design-time error: The tag helper 'textarea' must not have C# in element's attribute declaration area.

然后我尝试:

<textarea asp-for="Doc" disabled='@(Model.MustDisable ? "disabled" : "")'></textarea>

,它没有显示任何设计时错误,但呈现如下: Model.MustDisable==true呈现disabled='disabled',而Model.MustDisable==false呈现disabled. 因此,文本区域将始终被禁用.

which did not show any design time error but it renders like this: Model.MustDisable==true renders disabled='disabled' AND Model.MustDisable==false renders disabled. So the text area will always be disabled.

然后我尝试过(删除了):

Then I tried (removing the 's):

textarea asp-for="Doc" disabled=@(Model.MustDisable ? "disabled" : "")></textarea>

没有显示任何设计时错误,但与上一个相同.

which did not show any design time error but it renders the same as the previous one.

如何正确实施此方法?

推荐答案

我在选择标签帮助程序中遇到了同样的问题,我尝试了几件事,但仍然有效. 试试这个-

I was facing the same issue with select tag helper, i tried few things and it worked. Try this-

<textarea asp-for="Doc" disabled="@(Model.MustDisable ? "disabled" : null)"></textarea>

这篇关于asp.net有条件地禁用标签助手(文本区域)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆