小编ins*_*fom的帖子

ASP.NET MVC3 fileupload无法正常工作

页面代码

<% using (Html.BeginForm())
   { %>
<fieldset>
    <legend>??????</legend>
    <input  type="file" name="File1" />
    <input  type="submit" value="??" />
</fieldset>
<%} %>
Run Code Online (Sandbox Code Playgroud)

行动代码

[HttpPost]
public ActionResult FileUpLoad(int id, FormCollection form)
{
    try
    {
        var model = db.ProjcetDeclare.First(c => c.id == id);

        if (Request.Files.Count==0)
        {
            return View();
        }
        string newFile=string.Empty;

        var File1 = Request.Files[0];
        if (File1.ContentLength == 0)
        {
        }
        newFile = model.Project.pname + DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetFileName(File1.FileName);
        File1.SaveAs(Server.MapPath("/????/" + newFile));

        model.XMCL = "/????/" + newFile;
        UpdateModel(model);
        db.SaveChanges();
        return RedirectToAction("Index");
    }
    catch
    {
        return View(); …
Run Code Online (Sandbox Code Playgroud)

asp.net file-upload asp.net-mvc-3

2
推荐指数
1
解决办法
2664
查看次数

标签 统计

asp.net ×1

asp.net-mvc-3 ×1

file-upload ×1