相关疑难解决方法(0)

ASP.NET MVC3 RAZOR:文件上载给出文件计数为零

我需要使用带有RAZOR的MVC3将多个文件上传到Web服务器.我有以下代码.在控制器中,我的文件数为零.如何更正它以获取上传的文件的实际数量并获取内容?

public class MyFileController : Controller
{

    public ActionResult MyFileProcessActionTest()
    {
        return View();
    }

    [HttpPost]
    public ActionResult MyFileProcessActionTest(IEnumerable<System.Web.HttpPostedFileBase> files)
    {

        int fileCount = files.Count<System.Web.HttpPostedFileBase>();
        return RedirectToAction("Index");
    }
}
Run Code Online (Sandbox Code Playgroud)

视图

@{
ViewBag.Title = "MyFileProcessActionTest";
}

<h2>MyFileProcessActionTest</h2>

@using (Html.BeginForm())
{

<input type="file" name="files" id="file1" />
<input type="file" name="files" id="file2" />

<input type="submit"  />

}
Run Code Online (Sandbox Code Playgroud)

读:

  1. 使用Ajax.BeginForm绑定HttpPostedFileBase

  2. ASP.NET MVC上传和下载文件 http://www.mikesdotnetting.com/Article/125/ASP.NET-MVC-Uploading-and-Downloading-Files

  3. 如何验证文件上载的文件类型?

  4. MVC 3文件上传和模型绑定

.net asp.net asp.net-mvc razor

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

标签 统计

.net ×1

asp.net ×1

asp.net-mvc ×1

razor ×1