Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using FileUploader and a view model to post
Message
De
28/02/2017 05:27:49
 
 
Information générale
Forum:
ASP.NET
Catégorie:
MVC
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Divers
Thread ID:
01648596
Message ID:
01648611
Vues:
31
>Hi everybody,
>
>I am wondering if anyone implemented the File Uploader with the ASP.NET MVC and Windows API. I'm having problems :(
>
>My last attempt is the following:
>
>I created this class
>
>
> public class FileUploadResult
>    {
>        public String FileName { get; set; }
>        public String Key { get; set; }
>        public int PercentComplete { get; set; }
>        public HttpPostedFile Content { get; set; }
>        
>        public string Type { get; set; }
>    }
>
>and in my JavaScript file I attempt to save file as the Content property. So far so good.
>
>However, I am unable to post that info using my model which is the following:
>
>
> public class EditMessageViewModel
>    {
>        public short FormType { get; set; }
>        public int MessageId { get; set; } // MessageID (Primary key)
>        //public byte ReciptType { get; set; } // ReciptType. Type of recipient.  1=Guest.
>        //public decimal ReciptId { get; set; } // ReciptID. ID of the recipient.  I.e. if recipient type is a guest, then guest_no.
>        public string Body { get; set; } // Body
>  //      public System.DateTime DateTime { get; set; } // date_time
>  //      public System.Nullable<System.DateTime> Delivered { get; set; } // delivered
>        public System.DateTime Expires { get; set; } // expires
>
>        public string MsgFrom { get; set; }
>
>        public string Subject { get; set; }
>
>        public List<FileUploadResult> Attachments { get; set; }
>
>        public List<GuestsList> Recipients { get; set; }
>    }
>
>However, when I try to post I'm getting the 'Bad Request' right away, so apparently I can not post such model back.
>
>So, how exactly should I post both my model and the files I'm trying to upload?

Multipart form data can contain a mix of files and (for example) json objects. But I haven't used the MVC FileUpoader and don't know whether you can add additional parts on the client side before posting.

In any case I don't see how you can create a valid FileUploadResult in javascript since it contains a HttpPostedFile instance and one of it's properties is a .NET stream.......
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform