adding fileupload

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Hello All , i need some help on this
i cant get Request.Files "it allways give me the count is 0"
I added this to create view

based on this article
https://www.nopcommerce.com/boards/t/20491/shipping-plugins-configuration-with-pop-up-window-beginform-helper.aspx

@using (Html.BeginForm("Create", "ArticleCategory",FormMethod.Post,  new { enctype = "multipart/form-data" }))


on _CreateOrUpdate.cshtml  i added
  <input id="FileBanner" type="file" />
              
on controller
[HttpPost, ParameterBasedOnFormNameAttribute("save-continue", "continueEditing")]
  
     public ActionResult Create(ArticleCategoryModel model, bool continueEditing)
        {
try
            {
                HttpPostedFileBase FileBanner= Request.Files["FileBanner"];
                string filename = Server.MapPath("~/Content/Images/" + FileBanner.FileName);
                fileLogo.SaveAs(filename);
                model.Banner= filename;


            }
            catch (Exception exc)
            {
                throw exc;
                SuccessNotification( _localizationService.GetResource("Admin.Articles.ArticleCategory.errorlogo"));
                return View(model);
            }

}


but still m getting  Request.Files["fileLogo"] null !!!
11 years ago
mrcooll020 wrote:
Hello All , i need some help on this
i cant get Request.Files "it allways give me the count is 0"
I added this to create view

based on this article
https://www.nopcommerce.com/boards/t/20491/shipping-plugins-configuration-with-pop-up-window-beginform-helper.aspx

@using (Html.BeginForm("Create", "ArticleCategory",FormMethod.Post,  new { enctype = "multipart/form-data" }))


on _CreateOrUpdate.cshtml  i added
  <input id="FileBanner" type="file" />
              
on controller
[HttpPost, ParameterBasedOnFormNameAttribute("save-continue", "continueEditing")]
  
     public ActionResult Create(ArticleCategoryModel model, bool continueEditing)
        {
try
            {
                HttpPostedFileBase FileBanner= Request.Files["FileBanner"];
                string filename = Server.MapPath("~/Content/Images/" + FileBanner.FileName);
                fileLogo.SaveAs(filename);
                model.Banner= filename;


            }
            catch (Exception exc)
            {
                throw exc;
                SuccessNotification( _localizationService.GetResource("Admin.Articles.ArticleCategory.errorlogo"));
                return View(model);
            }

}


but still m getting  Request.Files["fileLogo"] null !!!


Try public ActionResult Create(ArticleCategoryModel model, bool continueEditing, HttpPostedFileBase FileBanner), MVC will bind the variable for you. :)
11 years ago
Thank you for your replay ,
i used this solution
I added this property to the model

   public IEnumerable<HttpPostedFileBase> Images { get; set; }


and added this code to view

 <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Banner):
            </td>
            <td class="adminData">
                <input type="file" name="Images" />
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Logo)
            </td>
            <td class="adminData">
                <input type="file" name="Images" />
            </td>
        </tr>



and everything is ok
11 years ago
mrcooll020 wrote:
Thank you for your replay ,
i used this solution
I added this property to the model

   public IEnumerable<HttpPostedFileBase> Images { get; set; }


and added this code to view

 <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Banner):
            </td>
            <td class="adminData">
                <input type="file" name="Images" />
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Logo)
            </td>
            <td class="adminData">
                <input type="file" name="Images" />
            </td>
        </tr>



and everything is ok


No problem. :)
7 years ago
mrcooll020 wrote:
Thank you for your replay ,
i used this solution
I added this property to the model

and everything is ok


Could you plz share your source code in your controller ?

I got the same your issues and could not fix it
4 years ago
Worked
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.