mvc文件页面怎么写

1.asp.net MVC 中文件下载的代码怎么写,不要求上传

控制器中写一个Action,有直接返回File()类型的,该方法其实就是下载

mvc文件页面怎么写

public ActionResult ExportFile()

{

Services.ImportAndExport manage = new Services.ImportAndExport();

string fileName = "abc.xls";//文件名

string filePath = "D:abc.xls";//文件路径

string MIME = "application/vnd.ms-excel";//文件类型

return File(filePath, MIME, fileName);

}

2.MVC界面如何下载pdf文件

在页面中直接打开PDF(要求机器已安装adobe reader),则只需要修改HTTP标头的参数:

将“Response.AddHeader("content-disposition", "attachment; filename=AdmissionTicket.pdf");”替换成“Response.AddHeader("content-disposition", string.Format("inline;filename={0}.pdf", admissionFormId));”

3.MVC2.0 如何下载文件

使用FileResult,注意指定合适的ContentType。

如下载ZIP文件:

var path = Server.MapPath("~/123.zip");

return File(path, "application/x-zip-compressed");

如果是word文档:

var path = Server.MapPath("~/123.doc");

return File(path, "application/msword");

你可以根据文件的后缀名来获取ContentType:

4.刚接触mvc,我需要把页面显示的内容导出到一个Excel文件

把导出做成一个单独的form块 在form中指定提交到哪个控制器中的哪个Action方法。

@using (Html.BeginForm()){ } 如果在BeginForm()没有参数的情况下默认是提交到和这个文件名一样的Action方法里面。

@using (Html.BeginForm("Create", "FileUpload", FormMethod.Post, new { enctype = "multipart/form-data" })) {}

这是MVC3的form写法。

在控制层写一个方法 这个方法里面在获取一次你页面显示的数据然后做处理导入到Excel中.