Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.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
C# 无法使用razor用图像填充表格_C#_.net_Entity Framework_Asp.net Core_Razor - Fatal编程技术网

C# 无法使用razor用图像填充表格

C# 无法使用razor用图像填充表格,c#,.net,entity-framework,asp.net-core,razor,C#,.net,Entity Framework,Asp.net Core,Razor,“IEnumerable”不包含“ImageName”的定义,并且找不到接受“IEnumerable”类型的第一个参数的可访问扩展方法“ImageName”(是否缺少using指令或程序集引用 是我目前遇到的错误,但是我的做法似乎是错误的,如果有人能帮助我或为我指出正确的方向,我将不胜感激。(我使用的是.net core 2.1,因为我的学校电脑不支持更高版本:/) 以下是视图: @model IEnumerable<Lab2Phase1.Models.Car> @{

“IEnumerable”不包含“ImageName”的定义,并且找不到接受“IEnumerable”类型的第一个参数的可访问扩展方法“ImageName”(是否缺少using指令或程序集引用

是我目前遇到的错误,但是我的做法似乎是错误的,如果有人能帮助我或为我指出正确的方向,我将不胜感激。(我使用的是.net core 2.1,因为我的学校电脑不支持更高版本:/)

以下是视图:

@model IEnumerable<Lab2Phase1.Models.Car>  

@{  
    ViewData["Title"] = "Index";  
}  

<strong>Index</strong>  

<p>  
    <a asp-action="Create">Create New</a>  
</p>  
<div class="col-md-8">
    <form action="/Cars" method="post">
        @Html.TextBox("search")
        <input type="submit" />
    </form>
</div>
<table class="table">  
    <thead>  
        <tr>  
            <th>  
                @Html.DisplayNameFor(model => model.Id)  
            </th>  
            <th>  
                @Html.DisplayNameFor(model => model.Model)  
            </th>  
            <th>  
                @Html.DisplayNameFor(model => model.TopSpeed)  
            </th>  
            <th>  
                @Html.DisplayNameFor(model => model.ImageName)
            </th>  
            <th></th>  
        </tr>  
    </thead>  
    <tbody>  
@foreach (var item in Model) {  
        <tr>  
            <td>  
                @Html.DisplayFor(modelItem => item.Id)  
            </td>  
            <td>  
                @Html.DisplayFor(modelItem => item.Model)  
            </td>  
            <td>  
                @Html.DisplayFor(modelItem => item.TopSpeed)  
            </td>  
            <td>  
                <img src="~/Content/images/@Html.DisplayFor(modelItem => modelItem.ImageName)" style="height:200px;width:200px;"/>  
            </td>  
            <td>  
                @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |  
                @Html.ActionLink("Delete", "Delete", new { id = item.Id }, new { onclick = "return confirm('Are you sure to delete?')" })  
            </td>  
        </tr>  
}  
    </tbody>  
</table>  
模型如下:

using System.ComponentModel.DataAnnotations;  
using System.ComponentModel.DataAnnotations.Schema;  

namespace Lab2Phase1.Models  
{  
    public class Car  
    {  
        [Key]
        public int Id { get; set; }  
        public string Model { get; set; }  
        public string TopSpeed { get; set; }  

        public string ImageName { get; set; }
    }  
}  
modelItem.ImageName)“style=”高度:200px;宽度:200px;“/>

应该是

假设您的
ImageName
是一个具有扩展名的文件名,在该路径中可用。

modelItem.ImageName)“style=“height:200px;width:200px;”/>

应该是

假设您的
ImageName
是一个扩展名为的文件名,在该路径中可用

using System.ComponentModel.DataAnnotations;  
using System.ComponentModel.DataAnnotations.Schema;  

namespace Lab2Phase1.Models  
{  
    public class Car  
    {  
        [Key]
        public int Id { get; set; }  
        public string Model { get; set; }  
        public string TopSpeed { get; set; }  

        public string ImageName { get; set; }
    }  
}