标题有点说明了一切。当我在 localhost 中运行它时,一切正常,今天我部署运行一些测试和 BAM!不工作。而且我由于某种原因无法显示错误,所以我不确定出了什么问题,或者真的如何调试它..
这是控制器:
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();
}
}
}
这是索引
@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" />
}
如果您还有其他需要尝试解决的问题,我很乐意更新问题。我对 MVC 相当陌生..