我做了一个动作,并使用Html.BeginForm上传图像文件
我的控制器名为ImagesTaple
就像这样:
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是这样的
@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> </td>
<td><input type="submit" name="submet" value="upload" /></td>
</tr>
</table>
}我的行动是
[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");
}现在当我按下我的子母按钮
我得到了这个错误信息
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我的代码中有什么问题,请帮助我。
发布于 2016-01-05 22:07:22
我只是拼错了,把ImagesTaple改成ImagesTable
https://stackoverflow.com/questions/34621340
复制相似问题