So I have a screen where the user can build up and email and attach files. When they click send I want to take them to a screen where they can review the email before sending it. (This Review screen is readonly with all the data in hidden inputs)
I can pass all my data to the Review screen, but when I click Send and submit the form I am losing reference to my uploaded files, while everything else is fine.
I know I can store the files in TempData and retrieve them again but I thought I would be able to do this on the view.
My attempt in my Review view at having hidden inputs for HttpPostedFileBase[] Files
int filePos = 0;
foreach (var n in Model.Files)
{
<input class="hidden" name="Files[@filePos].ContentLength" value="@Model.Files[filePos].ContentLength" />
<input class="hidden" name="Files[@filePos].ContentType"value="@Model.Files[filePos].ContentType" />
<input class="hidden" name="Files[@filePos].FileName" value="@Model.Files[filePos].FileName"/>
<input class="hidden" name="Files[@filePos].InputStream" value="@Model.Files[filePos].InputStream"/>
filePos++;
}
When I check the model on post back the HttpPostedFileBase[] Files
has two objects but both are null. I feel like its the InputStream
part that is not allowing this to work as it itself is an object.
Does anyone know how to get this method to work or have a better solution for maintaining files?
You cannot preset or change input file elements. This is invalid to prevent upload of any file by changing the input file element with javascript eg.
If you could, anyone could do it and upload any file from your local drive.
The description, which you can find here does not show any 'set value' function.