本文主要是介绍[Asp.net] MVC5 上传文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
控制器名 UploadTest
里面新两个Action, 分别为Upload()和SaveAs()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;namespace UploadFileTest.Controllers
{public class UploadTestController : Controller{// GET: UploadTestpublic ActionResult Index(){return View();}//这个view是用来选择上传文件的public ActionResult Upload(){return View();}//这个action是用来接收文件并保存在服务器上[HttpPost]public ActionResult SaveAs(HttpPostedFileBase MyFile){//得到的名字是文件在本地机器的绝对路径var strLocalFullPathName = MyFile.FileName;//提取出单独的文件名,不需要路径var strFileName = Path.GetFileName(strLocalFullPathName);//定义服务器的文件夹,用来保存文件var strServerFilePath = Server.MapPath("/docs/");/
这篇关于[Asp.net] MVC5 上传文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!