【问题标题】:how to upload file in Strong-Type view in ASP.NET MVC如何在 ASP.NET MVC 的强类型视图中上传文件
【发布时间】:2013-08-26 08:53:00
【问题描述】:

我用:

@using (Html.BeginForm("UploadPackage", "Manager"))

将 webForm 数据发送到UploadPackage 操作。

现在我在该强类型视图中添加一个类型为 file(< input type = "file" />) 的输入标签。 我想做的是:如何在我的 Action 中从 webForm(包括文件)中获取所有数据并进行处理?

【问题讨论】:

  • 任何帮助将不胜感激!!!

标签: asp.net-mvc file-upload


【解决方案1】:

视图中的表单:

@using (Html.BeginForm("FileUpload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{ 
     @Html.ValidationSummary();
     <ol>
     <li class="lifile">
     <input type="file" id="fileToUpload" name="file" />
     <span class="field-validation-error" id="spanfile"></span>
     </li>
     </ol>
     <input type="submit" id="btnSubmit" value="Upload" />
}

在控制器方面:

[HttpPost]
public ActionResult FileUpload(HttpPostedFileBase file)
{
     // Implementation
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多