2017-03-20 2 views
1

Ich habe ein Problem mit der Bindung geschachtelte IFormFile in .NET Core-MVC-Projekt. Wenn ich meine IFormFile im verschachtelten Ansichtsmodell einbette, ist sie nicht an den Post gebunden. Zum Beispiel funktioniert das nicht:IFormFile ist nicht gebunden, wenn im Ansichtsmodell verschachtelt

public class SomeVM 
{ 
    public GalleryVM Gallery { get; set; } 
} 
public class GalleryVM 
{ 
    public IFormFile UploadingImage { get; set; } 
    //gallery properties... 
} 

Ausblick:

@model SomeVM 

    <form method="post" enctype="multipart/form-data"> 
    <input type="file" name="Gallery.UploadingImage" /> 
    <input type="submit" value="save" /> 
    </form> 

Einige Code der Kürze halber weggelassen wurde.

Antwort

1

Ich fand die Lösung dazu, also möchte ich es mit Ihnen teilen. Ich fand, dass es bekannt Problem ist und es sollte gelöst werden in .net Kern 2.0 issue on github

Aktuelle Hack ist, einige zusätzliche Daten beim Hochladen von Datei zu senden.

public class SomeVM 
{ 
    public GalleryVM Gallery { get; set; } 
} 
public class GalleryVM 
{ 
    public IFormFile UploadingImage { get; set; } 
    public bool FormFileHack { get; set; } 
    //gallery properties... 
} 

//the view .cshtml 

<input type="file" name="Gallery.UploadingImage" /> 
<input type="hidden" name="Gallery.FormFileHack" /> 
Verwandte Themen