Here is my code -
//in Profile.cshtml @{ ViewBag.Title = "Profile"; } <h2>Profile</h2> @using (Html.BeginForm("Upload", "Profile", FormMethod.Post, new { enctype = "multipart/form-data" })) { <input type="file" name="file" /> <input type="submit" value="OK" /> } In my controller (ProfileController.cs) I have -
namespace MvcApplication1.Controllers { public class ProfileController : Controller { public ActionResult Index() { return View(); } public ActionResult Profile() { return View(); } [HttpPost] public ActionResult Upload(HttpPostedFileBase file) { if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Media/uploads"), fileName); file.SaveAs(path); } return RedirectToAction("Profile"); } } }
but everytime I click on "OK" to upload the file, I get this error - localhost:12345/Profile/Upload - Internet explorer can not display this webpage.
I have a method called Upload in my Profile controller that should accept this file.
What am I missing?