上传文件时找不到资源错误
Resource Cannot be found error when uploading a file
我是 ASP.NET MVC 方面的新手,所以:
我已经尽力搜索与此类似的问题,但找不到与我的问题直接相关的任何内容。
在我的一个视图中,有一个上传对话框。选择文件效果很好,但是当我按下上传时,我在浏览器中收到一条错误消息,显示 Resource Cannot be found error
。
这是我控制器中的方法:
[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase uploadFile)
{
HttpPostedFileBase File = Request.Files["uploadFile"];
if (File != null)
{
//If this is True, then its Working.,
}
if (uploadFile.ContentLength > 0)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("C:\inetpub\wwwroot\MarketPlace\Uploads"),
Path.GetFileName(uploadFile.FileName));
uploadFile.SaveAs(filePath);
}
return View();
}
这是视图:
@using (Html.BeginForm("Upload", "FileUpload", "MarketPlace", System.Web.Mvc.FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="wrapper">
<section class="col-sm-6">
<section class="panel">
<header class="panel-heading">
<p> Uploads</p>
</header>
<section class="panel">
<table>
<tr>
<td>Type: </td>
<td><bold>@ViewBag.Type</bold></td>
</tr>
<tr>
<td>Name: </td>
<td><bold>@ViewBag.Name</bold></td>
</tr>
</table>
<input id="uploadFile" name="uploadFile" type="file" />
<br />
<input type="submit" value="Upload File" id="btnSubmit" />
</section>
</section>
</section>
</div>
}
请帮我解决我的错误
@using (Html.BeginForm("UploadFile", "MarketPlace", System.Web.Mvc.FormMethod.Post, new { enctype = "multipart/form-data" })) ...
现在我做对了(从我的一个项目中复制的)
我是 ASP.NET MVC 方面的新手,所以:
我已经尽力搜索与此类似的问题,但找不到与我的问题直接相关的任何内容。
在我的一个视图中,有一个上传对话框。选择文件效果很好,但是当我按下上传时,我在浏览器中收到一条错误消息,显示 Resource Cannot be found error
。
这是我控制器中的方法:
[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase uploadFile)
{
HttpPostedFileBase File = Request.Files["uploadFile"];
if (File != null)
{
//If this is True, then its Working.,
}
if (uploadFile.ContentLength > 0)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("C:\inetpub\wwwroot\MarketPlace\Uploads"),
Path.GetFileName(uploadFile.FileName));
uploadFile.SaveAs(filePath);
}
return View();
}
这是视图:
@using (Html.BeginForm("Upload", "FileUpload", "MarketPlace", System.Web.Mvc.FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="wrapper">
<section class="col-sm-6">
<section class="panel">
<header class="panel-heading">
<p> Uploads</p>
</header>
<section class="panel">
<table>
<tr>
<td>Type: </td>
<td><bold>@ViewBag.Type</bold></td>
</tr>
<tr>
<td>Name: </td>
<td><bold>@ViewBag.Name</bold></td>
</tr>
</table>
<input id="uploadFile" name="uploadFile" type="file" />
<br />
<input type="submit" value="Upload File" id="btnSubmit" />
</section>
</section>
</section>
</div>
}
请帮我解决我的错误
@using (Html.BeginForm("UploadFile", "MarketPlace", System.Web.Mvc.FormMethod.Post, new { enctype = "multipart/form-data" })) ...
现在我做对了(从我的一个项目中复制的)