2016-04-12 8 views
2

ビューモデル(以下を参照)で検証された画像アップロードフィールドと名前フィールドを含むフォームを作成しようとしています。IFormFileをMVC6のビューモデルに配置する方法

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) 

コード:

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; } 
    } 
} 

は、私が何をしないのです問題は、私は、Visual Studio(サイトを開始)で、このクラスまたはヒットのプレイを考慮して、私のデータベースを移行するとき、私は次のエラーを取得することです?

答えて

2

コードに間違いがないことが分かりました。ビューを作成するときに、私は単にData Context Classを誤って選択しました。EFはビューモデルを気にしませんでした(ビューモデルをデータベースの近くに置くべきではありません)。

0

加えて、あなたはどのようにいずれか、モデルビューからファイルサイズをして下さい検証する方法についてこの

[FileExtensions(Extensioins="jpg,jpeg,png,pdf")] 
public IFormFile ImageUpload {get; set;} 

のようなモデルビューからファイルの拡張子を検証することができますか?

関連する問題