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="上传" />
    }

     
  • 相关阅读:
    预定义规则 取范围数据
    oracle table 数组的赋值方法
    java 缓存读写
    webpack
    vscode setting
    webpack babel
    共享你的vscode配置
    github API很丰富
    tips
    todo
  • 原文地址:https://www.cnblogs.com/ly-03-04/p/12303904.html
Copyright © 2011-2022 走看看