Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, February 6, 2015 10:48 AM
I have a model that has two properties and I need they need to be a collection of files, please help me fix my codes for these in my model and web api
model
public class tManagement
{
public HttpPostedFileBase ClientFile1 { get; set; }
public HttpPostedFile ClientFile2 { get; set; }
}
The Api controller (POST) will instantiate the model and assign the collection of files please me fix this two sets of codes to work together.
[System.Web.Http.HttpPost]
[System.Web.Http.HttpPost]
public HttpResponseMessage Post(IEnumerable<HttpPostedFileBase> UploadFiles)
{
HttpResponseMessage result = null;
var MoveFiles = new tManagement();
MoveFiles.ClientFile2 = UploadFiles.GetEnumerator(); <-- error 1
}
Error message 1
Cannot implicitly convert type 'System.Collections.Generic.IEnumerator<System.Web.HttpPostedFileBase>' to 'System.Web.HttpPostedFile'
All replies (1)
Friday, February 6, 2015 11:16 AM âś…Answered
HttpPostedFileBase and HttpPostedFile have the same properties, but are not related class wise, so you can not cast one to the other (they are completely different objects to .net). HtppPostedFileBase is usually used for unit test mocking.
here is a good explanation: