Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 用页面中的图像替换表值中的true或false_Html_Asp.net Core_Razor Pages - Fatal编程技术网

Html 用页面中的图像替换表值中的true或false

Html 用页面中的图像替换表值中的true或false,html,asp.net-core,razor-pages,Html,Asp.net Core,Razor Pages,嗨,我在剃须刀页面编码。我有一个表,其中一个值是布尔值,此时表中显示的是true或false。我想用wwwroot文件夹中的图像切换这些值。带有布尔值的变量是@tool.followed 我的HTML代码 <table border ="1" class="table table-sortable"> <thead> <tr> <td><b>Verk

嗨,我在剃须刀页面编码。我有一个表,其中一个值是布尔值,此时表中显示的是true或false。我想用wwwroot文件夹中的图像切换这些值。带有布尔值的变量是@tool.followed

我的HTML代码

<table border ="1" class="table table-sortable">
    <thead>
        <tr>
            <td><b>Verktøy Nummer</b></td>
            <th>Modell</th>
            <td><b>RFID nummer</b></td>
            <th>Kategori</th>
            <th>Utlånt</th>
            <td><b>Siste ansvarlige person</b></td>
        </tr>
    </thead>
    <tbody>
        @foreach (var tool in Model.Tools) //Get the nessecary Tools from the tools Model from Tools.csgtml.cs
        {
        <tr>
            <td>@tool.ToolNumber</td>

            <td><a asp-page="/Tools/Details" asp-route-ID="@tool.ToolId">@tool.Model</a> </td>

            <td> @tool.ToolId </td>
            <td> @tool.Category</td>            
            <td> @tool.Borrowed</td>
            <td><a asp-page="/Employees/Details" asp-route-ID="@tool.EmployeeId">@tool.EmployeeName</a> </td>
        </tr>
        }
    </tbody>
</table>


维克特·努默
模特儿
无线射频识别器
卡泰戈里
Utlånt
安斯瓦利格姐妹酒店
@foreach(Model.Tools中的var-tool)//从Tools.csgtml.cs的工具模型中获取nessecary工具
{
@工具号
@工具模型
@tool.ToolId
@工具类别
@工具,借来的
@tool.EmployeeName
}

如果您想根据
@工具的值添加图像。借用的
。您可以使用。下面是一个演示:

wwwroot结构:

cshtml:

<table border="1" class="table table-sortable">
    <thead>
        <tr>
            <td><b>Verktøy Nummer</b></td>
            <th>Modell</th>
            <td><b>RFID nummer</b></td>
            <th>Kategori</th>
            <th>Utlånt</th>
            <td><b>Siste ansvarlige person</b></td>
        </tr>
    </thead>
    <tbody>
        @foreach (var tool in Model.Tools) //Get the nessecary Tools from the tools Model from Tools.csgtml.cs
        {
        <tr>
            <td>@tool.ToolNumber</td>

            <td><a asp-page="/Tools/Details" asp-route-ID="@tool.ToolId">@tool.Model</a> </td>

            <td> @tool.ToolId </td>
            <td> @tool.Category</td>
            <td><img src="@(tool.Borrowed?"/imgs/true.jpg":"/imgs/false.jpg")" /></td>
            <td><a asp-page="/Employees/Details" asp-route-ID="@tool.EmployeeId">@tool.EmployeeName</a> </td>
        </tr>
        }
    </tbody>
</table>
结果:

您好,我确实收到一个CS0266错误:无法将类型“bool”隐式转换为“bool”。存在显式转换(是否缺少转换?)。在我的工具模型中,我将借用值设置为可为空的布尔值。在cshtml.cs OnGet方法中,我使用IEnumerable方法作为搜索词,从我的工具dbSet获取上下文。你知道如何修复这个错误吗?我让它工作了。我只需要改变一下,我的工具类没有作为可空bool的借来值。并在我的数据库中插入False/True
 [BindProperty]
            public List<Tool> Tools { get; set; }
            public void OnGet()
            {
                Tools = new List<Tool> { new Tool { Borrowed = true }, new Tool { Borrowed = false }, new Tool { Borrowed = false } };
            }