I can upload files to folder but I cannot save the file info to db.
I am using ng-upload and I want to add $scope.recipeID
to the upload request to controller, I tried the following
Upload.upload({
url: '/Files/Upload/',
data: {
files: $scope.SelectedFiles,
'RecipeId': $scope.recipeID
}
then called it in the controller like so
[HttpPost]
public ContentResult Upload()
{
string path = Server.MapPath("~/Uploads/");
foreach (string key in Request.Files)
{
HttpPostedFileBase postedFile = Request.Files[key];
postedFile.SaveAs(path + postedFile.FileName);
Models.File recipefile = new Models.File();
recipefile.Name = postedFile.FileName; //not saving to db
recipefile.Path = path; //not saving to db
recipefile.RecipeId = postedFile.RecipeId; //Error on .RecipeId
db.Files.Add(recipefile);
}
return Content("Success");
}
but it returned an error and postedFile.FileName
and path
is not saving to db, even file id was not saving.
HttpPostedFileBase does not contain a definition of 'RecipeId'