我在asp.net mvc网站上设置了一个上传文件功能。代码不会抛出任何错误,但我选择上传的文件不会存储在指定位置。以下是我的代码。
控制器
public ActionResult uploadCourseList(HttpPostedFileBase file)
{
var filename = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data"), filename);
file.SaveAs(path);
KuPlanEntities db = new KuPlanEntities();
var user = "000000001";
var userIdvar = (from userId in db.AspNetUsers
where userId.Id == user
select userId.Id).ToString();
var stuList = (from users in db.AspNetUsers
where users.advisor == user
select new listStudentViewModel { Id = users.Id, fname = users.fname, lname = users.lname });
return View("~/Views/ManageStudentCourses/Index.cshtml", stuList);
}
查看
<div id="uploadCourseList">
@using (Html.BeginForm("uploadCourseList", "ManageStudentCourses", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<table class="courseListTable">
<tr>
<th colspan="4">
Upload Course List
</th>
</tr>
<tr>
<td>
Select a file:
</td>
<td>
<input type="file" name="file" id="file" />
</td>
<td>
<input type="submit">
</td>
</tr>
</table>
}
</div>