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

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

问题描述

我使用的:

@using(Html.BeginForm(UploadPackage,经理))

要WebForm的数据发送到 UploadPackage 操作。

to send webForm data to UploadPackage 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天全站免登陆