【问题标题】:File Uploading in Asp.net MVC and geting the file through FormCollection在 Asp.net MVC 中上传文件并通过 FormCollection 获取文件
【发布时间】:2012-03-17 06:32:22
【问题描述】:

我正在用 asp.net mvc 开发一个应用程序,我想在其中上传一个文件。在视图端,当我的视图调用控制器时,我在运行时呈现我的上传文件字段,它提供 FormCollection 中的所有数据,在控制器端,我只能以字符串和请求的形式获取上传文件的名称.File[0].count 等于零。现在我该如何解决这个问题。

代码可以按需共享。

问候

【问题讨论】:

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


【解决方案1】:

尝试将其添加到您的 View

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
   <input type="file" id="file" name="file" />
   <input type="submit" value="upload" />
}

在您的controller 文件中:

[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
    return View();
}

【讨论】:

    猜你喜欢
    • 2011-06-22
    • 2021-12-10
    • 2012-12-25
    • 1970-01-01
    • 2011-07-08
    • 2023-04-03
    • 1970-01-01
    • 2010-11-01
    • 1970-01-01
    相关资源
    最近更新 更多