无法使用母版页在mvc 3中上传文件

时间:2014-01-23 08:35:25

标签: c# asp.net asp.net-mvc-3

我需要在.aspx页面的asp.net mvc3上传文件。虽然上传文件而不使用母版页,但一切正常。如果我使用母版页无法上传文件。

请帮助我。

在控制器

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
{
    if (uploadFile.ContentLength > 0)
    {
        string filePath = Path.Combine(Server.MapPath("~/Content/Image"),
                                       Path.GetFileName(uploadFile.FileName));
        uploadFile.SaveAs(filePath);
    }
    return View();
}

这是我的.aspx视图

<% using (Html.BeginForm("FileUpload","Home", 
                    FormMethod.Post, new { enctype = "multipart/form-data" }))
        {%>
        <input name="uploadFile" type="file" />
        <input type="submit" value="Upload File" />
<%} %>

0 个答案:

没有答案
相关问题