Title kind of says it all. When I am running this in localhost everything works fine, today I deployed to run some testing and BAM! not working. And I for some reason cannot enable the errors to display so I am not sure what is wrong, or really how to even debug this..
Here is the controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DarkRobot.Models;
using System.Web.Helpers;
using System.IO;
namespace DarkRobot.Controllers
{
[Authorize]
public class UploadController : Controller
{
//
// GET: /Upload/
private DarkRobotEntities1 db = new DarkRobotEntities1();
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(HttpPostedFileBase file, string name)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("/Images"), fileName);
file.SaveAs(path);
Image image = new Image();
image.RelativeLocation = "/Images/" + file.FileName;
image.Title = name;
db.Images.Add(image);
db.SaveChanges();
}
return RedirectToAction("Confirm");
}
public ActionResult Confirm()
{
return View();
}
}
}
And here is Index
@using (Html.BeginForm("Index", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<br />
<input type="text" name="name" />
<br />
<input type="submit" value="OK" />
}
If there is anything else you need to try to figure this out, I will gladly update the question. I am fairly new to MVC..
If the same code works in your development, I Strongly believe it is a permission issue. Make sure the directory you are trying to upload to, have sufficient permissions to write a file to that.