asp-for 和 if 条件在同一组件中 [英] asp-for and if condition in same component

查看:45
本文介绍了asp-for 和 if 条件在同一组件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在组件内使用 asp-for 和条件,但我找不到办法做到这一点.

i'm trying to use a asp-for and a condition inside a component but i can't find a way to do that.

这是我的代码

<label asp-for="@Model.Selected">
    @Model.Nome
    <input type="checkbox" asp-for="@Model.Selected"  />
</label>

我想要点赞

<label asp-for="@Model.Selected">
    @Model.Nome
    <input type="checkbox" asp-for="@Model.Selected" @((Model.Unlucky) ? "disabled")  />
</label>

我如何在 ASP.Net Razor 中执行此操作

How can i do this in ASP.Net Razor

推荐答案

我认为您可以在该变量之后添加一个新变量并构建字符串以禁用输入:

I think you can add a new variable after that one and build the string to disable the input:

           @{
                var disabledTag = Model.Unlucky == null ? "disable" : "";
            }
            <input type="checkbox" asp-for="@Model.Selected" @disabledTag) />

这篇关于asp-for 和 if 条件在同一组件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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