Click here to Skip to main content
15,867,780 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys i need help !! In MVC C#
- i have 5 input file for uploading images and 5 text box and 5 check box
- each input file previews the chosen image and he can choose the thumbnail by choosing the check box
# problem im facing #

in controller im getting only four images (or)path from trough FROM COllection

HttpPostedFileBase File1 = Request.Files["fileupload1"];
HttpPostedFileBase File2 = Request.Files["fileupload2"];
HttpPostedFileBase File3 = Request.Files["fileupload3"];
HttpPostedFileBase File4 = Request.Files["fileupload4"];
HttpPostedFileBase File5 = Request.Files["fileupload5"];

and for the fourth one im getting null ??? i have checked the id's nothing wrong in them ..
what am i doing wrong here .. ???

HTML
Here is my view code >>

@using (Html.BeginForm("AddPortfolio", "Portfolio", FormMethod.Post, new { id = "form_model_index", enctype = "multipart/form-data", autocomplete = "off" }))
{
<input type="file" name="fileupload1" id="fileupload1" accept="image/*" >
<input type="file" name="fileupload2" id="fileupload2" accept="image/*" >
<input type="file" name="fileupload3" id="fileupload3" accept="image/*" >
<input type="file" name="fileupload4" id="fileupload4" accept="image/*" >
<input type="file" name="fileupload5" id="fileupload5" accept="image/*" >
<br/>
<input type="submit" class="button-for-applied" value="save">
}
Posted
Updated 13-Jan-16 20:55pm
v3
Comments
Raje_ 14-Jan-16 1:32am    
Share your view page code. Did you mean for fifth one you are getting null??
prabashanash 14-Jan-16 2:54am    
# >> Im getting null in fourth File .
Here is my view code >>

@using (Html.BeginForm("AddPortfolio", "Portfolio", FormMethod.Post, new { id = "form_model_index", enctype = "multipart/form-data", autocomplete = "off" }))
{
<input type="file" name="fileupload1" id="fileupload1" accept="image/*" >
<input type="file" name="fileupload2" id="fileupload2" accept="image/*" >
<input type="file" name="fileupload3" id="fileupload3" accept="image/*" >
<input type="file" name="fileupload4" id="fileupload4" accept="image/*" >
<input type="file" name="fileupload5" id="fileupload5" accept="image/*" >
<br/>
<input type="submit" class="button-for-applied" value="save">
}
Abhinav S 14-Jan-16 3:02am    
If you are trying to upload the same image set, upload the fourth image in another upload box. COuld be an issue with the image format.

1 solution

You can use HttpPostedFileBase :

HTML
<input type="file" name="fileupload1" id="fileupload1" accept="image/*" >
<input type="file" name="fileupload2" id="fileupload2" accept="image/*" >
<input type="file" name="fileupload3" id="fileupload3" accept="image/*" >
<input type="file" name="fileupload4" id="fileupload4" accept="image/*" >
<input type="file" name="fileupload5" id="fileupload5" accept="image/*" >


Your controller action should be like this :

C#
public ActionResult UploadImage(IEnumerable<HttpPostedFileBase> files)
{
  //your code
if (files != null)
                {
 foreach (var file in files)
                    {
              //upload your file
         }
     }
 }


Good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900