简体   繁体   English

如何将图片包含到我的 Razor Page 项目中?

[英]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.

相关问题 如何将剃刀页面包含在另一个剃刀页面中? - How to include a razor page to another razor page? 如何在项目安装中包含 .NET Framework? - How do I include .NET Framework alongside my project installation? 我如何在我的网站上显示我的Facebook图片 - How do I display my facebook pictures on my site 如何根据网页上的链接从网页下载图片? - How do I download pictures from a webpage based on their LINKS on this page? 如何在pdftable中添加单元格并将图片插入其中 - How do I add cell in my pdftable and insert pictures into it 如何使我的安装项目在Winform应用程序中包含数据库(.sdf)文件? - How Do I make my Setup Project Include my Database (.sdf) file along with the winform application? Razor Pages:如何在部分页面中包含 pagesection? - Razor Pages: How to include pagesection in a partial page? 如何使用应用程序代表页面将链接,图片等发布到我的Facebook页面? - How can I post links, pictures etc to my facebook page on behalf of my page using an app? 如何在 MVC3 的 Razor 页面上使用枚举? - How can I use Enums on my Razor page in MVC3? 当打包到VSIX中时,如何包括我的项目模板程序集 - How do I include my assemblies for a Project Template when packaged in a VSIX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM