zoukankan      html  css  js  c++  java
  • MVC上传图片

    //控制器
    using
    System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.IO;//上传文件的数据流 namespace UploadImg.Controllers { public class UploadController : Controller { // GET: Upload public ActionResult Add() { return View(); } [HttpPost] public void Add(HttpPostedFileBase imgFile) { //判断是否上传图片 if (imgFile!=null) { //虚拟路径 var p = "/Content/Imgs/" + Path.GetFileName(imgFile.FileName); imgFile.SaveAs(Server.MapPath(p)); } } } }

    //页面


    @{
    ViewBag.Title = "Add";
    }

    
    

    <h2>Add</h2>
    @*enctype = "multipart/form-data"上传文件必须的属性*@
    @using (Html.BeginForm("Add", "Upload", FormMethod.Post, new { @enctype = "multipart/form-data" }))
    {
    <input id="File1" type="file" name="imgFile" />
    <input id="Submit1" type="submit" value="上传" />
    }

     
  • 相关阅读:
    Spring
    数据库架构
    Spring
    Spring
    Spring
    服务的有状态和无状态(转)
    Java基础
    Ubuntu
    Ubuntu
    Ubuntu
  • 原文地址:https://www.cnblogs.com/ly-03-04/p/12303904.html
Copyright © 2011-2022 走看看