如何在MVC6中将IFormFile放入视图模型

Jam*_*mes 5 c# asp.net asp.net-core-mvc asp.net-core

我正在尝试创建一个具有图像上载字段和名称字段的表单,并使用视图模型对其进行验证(请参见下文)。问题是,当我将数据库迁移到该类帐户或在Visual Studio中点击播放(启动站点)时,出现以下错误:

InvalidOperationException: The property 'ImageUpload' on entity type 'BallWallWebApp.ViewModels.Slides.CreateSlideViewModel' has not been added to the model or ignored.
Microsoft.Data.Entity.Metadata.Conventions.Internal.PropertyMappingValidationConvention.Apply(InternalModelBuilder modelBuilder)
Run Code Online (Sandbox Code Playgroud)

码:

using Microsoft.AspNet.Http;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace BallWallWebApp.ViewModels.Slides
{
    public class CreateSlideViewModel
    {
        [Required]
        public int WallId { get; set; }

        [Required]
        [Display(Name = "Slide Name")]
        [DataType(DataType.Text)]
        public string Name { get; set; }

        [Required]
        [Display(Name = "Slide image file")]
        [DataType(DataType.Upload)]
        public IFormFile ImageUpload { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想念什么?

Jam*_*mes 2

事实证明代码没有任何问题,我只是Data Context Class在创建视图时意外选择了 a ,这意味着EF开始关心视图模型,这是绝对不应该的(视图模型不应该靠近数据库)。