[英]How do I include pictures into my Razor Page project?
I am making a project that is supposed to act as a movie rental website.我正在制作一个应该充当电影租赁网站的项目。 I need to have cover pages for all of the movies in my selection.我需要为我选择的所有电影制作封面。 How would I go about doing this in my project?我 go 如何在我的项目中执行此操作? I would prefer HTML if I could just because i'm the most comfortable with that.如果可以的话,我更喜欢 HTML,因为我对此最满意。 I am using Razor Pages .NET CORE and my language is C#. I also have all the images I need stored into a file already in the program so that is done.我正在使用 Razor 页 .NET 核心,我的语言是 C#。我还将我需要的所有图像存储到程序中已经存在的文件中,这样就完成了。 Here is my code:这是我的代码:
for my models class (this is only showing the model for cover photo):对于我的模型 class(这仅显示封面照片的 model):
[Display(Name = "Cover Photo")]
[Column(TypeName = "varchar(128)")]
public string Cover_Photo { get; set; }
Here is the cshtml(I included everything here):这是 cshtml(我在这里包含了所有内容):
<p>
<a asp-page="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Movie[0].Title)
</th>
<th>
@Html.DisplayNameFor(model => model.Movie[0].RatingId)
</th>
<th>
@Html.DisplayNameFor(model => model.Movie[0].Description)
</th>
<th>
@Html.DisplayNameFor(model => model.Movie[0].Length)
</th>
<th>
@Html.DisplayNameFor(model => model.Movie[0].GenreId)
</th>
<th>
DVD / BluRay
</th>
<th>
@Html.DisplayNameFor(model => model.Movie[0].Cover_Photo)
</th>
<th>
@Html.DisplayNameFor(model => model.Movie[0].Release_Date)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Movie) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.Rating.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.Length)
</td>
<td>
@Html.DisplayFor(modelItem => item.Genre.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Is_Dvd) / @Html.DisplayFor(modelItem => item.Is_BluRay)
</td>
<td>
@Html.DisplayFor(modelItem => item.Cover_Photo)
</td>
<td>
@Html.DisplayFor(modelItem => item.Release_Date)
</td>
<td>
<a asp-page="./Edit" asp-route-id="@item.MovieId">Edit</a> |
<a asp-page="./Details" asp-route-id="@item.MovieId">Details</a> |
<a asp-page="./Delete" asp-route-id="@item.MovieId">Delete</a> |
<a asp-page="../Reviews/Create" asp-route-id="@item.MovieId">Add Review</a>
</td>
</tr>
}
</tbody>
</table>
I also have a cshtml.cs file but im not sure what that is for or what goes in there.我还有一个 cshtml.cs 文件,但我不确定它的用途或内容。 Thank you!谢谢! all help is appricated!所有的帮助都是适用的!
All the information is in the table but I cant seem to figure out how to get the pictures to show.所有信息都在表中,但我似乎无法弄清楚如何显示图片。
That is because you do not use <img />
element.那是因为你没有使用<img />
元素。 Change like below:更改如下:
<img src="@item.Cover_Photo" />
Be sure you have photos in wwwroot/Pictures
:确保您在wwwroot/Pictures
中有照片:
Also be sure your Cover_Photo
property stored value like below:还要确保您的Cover_Photo
属性存储的值如下所示:
public List<TestModel> Movie { get; set; }
public IActionResult OnGet()
{
Movie = new List<TestModel>()
{
new TestModel(){ Cover_Photo="Pictures/book1.jpg"},
new TestModel(){ Cover_Photo="Pictures/book2.jpg"}
};
return Page();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.