<pre> [HttpPost] [ValidateAntiForgeryToken] public ActionResult UploadImage(ImageModel collection,HttpPostedFileBase uploadFile) { if (uploadFile != null && uploadFile.ContentLength > 0) { string imgname = Path.GetFileName(uploadFile.FileName); string imgext = Path.GetExtension(imgname); if (imgext == ".jpg" || imgext == ".png") { string imgPath = Path.Combine(Server.MapPath("~/gallery/"), imgname); int success = 0; ImageModel imgmodel = new ImageModel(); imgmodel.img_ext = imgext; imgmodel.img_url = imgPath; imgmodel.imgName = imgname; success = IImageRep.AddImage(imgmodel); uploadFile.SaveAs(imgPath); } } return View(); }
@using (Html.BeginForm("UploadImage", "Image", FormMethod.Post, new { entype = "multipart/form-data" })) { @Html.AntiForgeryToken() <h4>tbl_Images</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <input type="file" name="uploadFile" id="uploadFile" /> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)