我的网站托管在 IIS7.5 我有一个控制器操作如下
[HttpPost]
public ActionResult Create(ClientDocument clientdocument,HttpPostedFileBase FilePath)
{
if (ModelState.IsValid)
{
try
{
if (FilePath != null && FilePath.ContentLength > 0)
{
var filename = Path.GetFileName(FilePath.FileName);
string ext = filename.Split(char.Parse(".")).LastOrDefault();
clientdocument.FilePath = clientdocument.Title + "." + ext;
var path = Path.Combine(Server.MapPath("~/Uploads"), clientdocument.Title + "." + ext);
FilePath.SaveAs(path);
db.ClientDocuments.Add(clientdocument);
db.SaveChanges();
return RedirectToAction("../");
}
}
catch(Exception ex)
{
return HttpNotFound("There Was A Problem Uploading File And Creating A Record");
}
}
ViewBag.ClientID = new SelectList(db.Clients, "ClientID", "FullName", clientdocument.ClientID);
return View(clientdocument);
}
当我单击按钮时,它会尝试上传文件,但随后显示以下错误消息
http 404 文件或目录未找到您要查找的资源可能已被删除、名称已更改或临时不可用
请协助如何配置 iis7.5 以上传此文件,而在 VS2010 中一切正常。
编辑
更改后@keshav 提到的视图:
@using (Html.BeginForm("Create", "ClientDocument", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Attach New Client Document</legend>
<div class="editor-label">
@Html.LabelFor(model => model.FilePath)
</div>
<div class="editor-field">
<input type="file" id="FilePath" name="FilePath" />
@Html.ValidationMessageFor(model => model.FilePath)
</div>
<fieldset>
}
和控制器:
[HttpPost,ActionName("Create")]
public ActionResult Create(ClientDocument clientdocument,HttpPostedFileBase FilePath)
{
if (ModelState.IsValid)
{
try
{
if (FilePath != null && FilePath.ContentLength > 0)
{
var filename = Path.GetFileName(FilePath.FileName);
string ext = filename.Split(char.Parse(".")).LastOrDefault();
clientdocument.FilePath = clientdocument.Title + "." + ext;
var path = Path.Combine(Server.MapPath("~/Uploads"), clientdocument.Title + "." + ext);
FilePath.SaveAs(path);
db.ClientDocuments.Add(clientdocument);
db.SaveChanges();
return RedirectToAction("Index", "Home");
}
}
catch(Exception ex)
{
return HttpNotFound("There Was A Problem Uploading File And Creating A Record");
}
}
ViewBag.ClientID = new SelectList(db.Clients, "ClientID", "FullName", clientdocument.ClientID);
return View(clientdocument);
}
我仍然遇到和以前一样的问题。