【发布时间】:2014-05-28 20:19:22
【问题描述】:
我有一个最近添加了文件附件功能的网站;然而,剑道.SaveUrl() 似乎没有“看到”控制器!我已经验证所有文件路径都是正确的。我在默认映射语句之前添加了自定义映射...浏览器不是问题,我尝试过 IE、Chrome、FireFox 和 Safari,同样的错误。请帮忙!
错误:
System.Web.HttpException (0x80004005): The controller for path '/Shared/RepairAttachment' was not found or does not implement IController.
Global.asax.cs 中的地图:
routes.MapRoute(
name: "/Shared/RepairAttachment",
url: "Controllers/RepairAttachmentsController/{Save}/{IEnumerable<HttpPostedFileBase>}",
defaults: new { controller = "RepairAttachmentsController", action = "Save", attachments = UrlParameter.Optional });
文件上传器代码:
@(Html.Kendo().Upload()
.ShowFileList(true)
.Async(async => async
.SaveUrl("SharedRepairAttachment")
)
.Name("frmUploadController")
.Multiple(true)
.Events(events => events
.Complete("onRepairAttachmentUploadComplete")
.Error("onRepairAttachmentUploadError")
)
)
控制器(部分):
public class RepairAttachmentsController : Controller
{
[HttpPost]
[HttpOptions]
public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments)
{
try
{
HarbisonFischerDBEntities db = new HarbisonFischerDBEntities();
foreach (var file in attachments)
{
Repair r = db.Repairs.Find(ViewBag.RepairID);
// Each Customer and repair gets their own folder
string srvrpath = Path.Combine(ConfigurationManager.AppSettings["ServerPathForFiles"].ToString(), r.CustomerLocation.Customer.OracleName);
srvrpath = Path.Combine(srvrpath, r.RepairID.ToString());
if (Directory.Exists(srvrpath) == false) { Directory.CreateDirectory(srvrpath); }
string fileName = Path.GetFileName(file.FileName); // Some browsers send file names with full path; we only care about the file name.
string destinationPath = Path.Combine(Server.MapPath(srvrpath), fileName);
file.SaveAs(destinationPath);
RepairAttachment ra = new RepairAttachment();
ra.FileName = file.FileName;
ra.Title = Path.GetFileNameWithoutExtension(file.FileName);
ra.RepairID = ViewBag.RepairID;
db.RepairAttachments.Add(ra);
db.SaveChanges();
}
}
catch (Exception ex)
{
Logic.ExceptionLogging.LogException("RepairAttachmentsController", ex, null, null);
return Json(new { status = "Upload Failed: " + ex.Message }, "text/plain");
}
return Json(new { status = "Upload succeeded." }, "text/plain");
}
【问题讨论】:
-
错误是
/Shared/RepairAttachment,不应该是/Shared/RepairAttachments吗? -
您的 Url 格式很有趣...从未见过“{IEnumerable
}”作为参数 - 不确定它如何/是否有效...请注意,您的示例未显示匹配的路线“ /Shared/RepairAttachment" url - 考虑添加到帖子中。
标签: c# asp.net-mvc asp.net-mvc-4 routes