首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mvc4上传文件我不能调用我的操作

mvc4上传文件我不能调用我的操作
EN

Stack Overflow用户
提问于 2016-01-05 21:14:42
回答 1查看 87关注 0票数 1

我做了一个动作,并使用Html.BeginForm上传图像文件

我的控制器名为ImagesTaple

就像这样:

代码语言:javascript
复制
    using System;
using System.IO;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using bootstrab1.Models;

namespace bootstrab1.Controllers
{
    public class ImagesTableController : Controller
    {
        private SpaDbEntities db = new SpaDbEntities();

        //
        // GET: /Images/

        public ActionResult Index()
        {
            return View(db.C_Images.ToList());
        }

        [HttpPost]
        public ActionResult UploadImg(HttpPostedFileBase image)
        {
            if (image.ContentLength > 0)
            {
                var FileFame = Path.GetFileName(image.FileName);
                var path = Path.Combine(Server.MapPath("~/Images/"), FileFame);
                image.SaveAs(path);
            }
            return RedirectToAction("Create");
        }
        //
        // GET: /Images/Details/

        public ActionResult Details(int id = 0)
        {
            C_Images c_images = db.C_Images.Find(id);
            if (c_images == null)
            {
                return HttpNotFound();
            }
            return View(c_images);
        }

        //
        // GET: /Images/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Images/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(C_Images c_images)
        {
            if (ModelState.IsValid)
            {
                db.C_Images.Add(c_images);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(c_images);
        }

        //
        // GET: /Images/Edit/5

        public ActionResult Edit(int id = 0)
        {
            C_Images c_images = db.C_Images.Find(id);
            if (c_images == null)
            {
                return HttpNotFound();
            }
            return View(c_images);
        }

        //
        // POST: /Images/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(C_Images c_images)
        {
            if (ModelState.IsValid)
            {
                db.Entry(c_images).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(c_images);
        }

        //
        // GET: /Images/Delete/5

        public ActionResult Delete(int id = 0)
        {
            C_Images c_images = db.C_Images.Find(id);
            if (c_images == null)
            {
                return HttpNotFound();
            }
            return View(c_images);
        }

        //
        // POST: /Images/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            C_Images c_images = db.C_Images.Find(id);
            db.C_Images.Remove(c_images);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}

我的BeginForm是这样的

代码语言:javascript
复制
@using (Html.BeginForm("UploadImg","ImagesTaple", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
  <table>
<tr>
    <td>file : </td>
    <td><input type="file" name="File" id="file" /></td>
</tr>
<tr>
     <td>&nbsp;</td>
     <td><input type="submit" name="submet" value="upload" /></td>
</tr>
  </table>  

}

我的行动是

代码语言:javascript
复制
 [HttpPost]
        public ActionResult UploadImg(HttpPostedFileBase image)
        {
            if (image.ContentLength > 0)
            {
                var FileFame = Path.GetFileName(image.FileName);
                var path = Path.Combine(Server.MapPath("~/Images/"), FileFame);
                image.SaveAs(path);
            }
            return RedirectToAction("Create");
        }

现在当我按下我的子母按钮

我得到了这个错误信息

代码语言:javascript
复制
Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /ImagesTaple/UploadImg

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0

我的代码中有什么问题,请帮助我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-05 22:07:22

我只是拼错了,把ImagesTaple改成ImagesTable

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34621340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档