无法在Asp.Net Core Mvc中的froms中上传多个文件

问题描述

我想创建一个多图像上传文件。我想这样创建:http://learningprogramming.net/net/asp-net-core-mvc/multiple-file-upload-in-forms-in-asp-net-core-mvc/

类似地,当我创建模型并进行迁移时,我发现了一个错误

test.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Practise.Models
{
    public class test
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public double Price { get; set; }
        public List<string> Photos { get; set; }
    }
}

错误

enter image description here

为此,我无法采取步骤创建多个文件上传。如何解决该问题。

解决方法

您需要建立一对多关系,对多张照片进行一次测试,因此您需要在数据库中具有两个表。 您可以这样设置模型:

public class test
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public double Price { get; set; }
        public List<Photo> Photos { get; set; }
    }
public class Photo
    {
        public string PhotoId { get; set; }
        public string Path { get; set; }
    }