如何在 ASP.NET MVC 中以强类型视图上传文件 [英] how to upload file in Strong-Type view in ASP.NET MVC

查看:22
本文介绍了如何在 ASP.NET MVC 中以强类型视图上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用:

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

将 webForm 数据发送到 UploadPackage 操作.

to send webForm data to UploadPackage action.

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

Now I add an input tag whose type is file(< input type = "file" />) in that strong-type view. What I want to do is: How can I get all data from webForm (including file) in my Action and handle them?

推荐答案

表单视图:

@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
}

这篇关于如何在 ASP.NET MVC 中以强类型视图上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆