[英]The resource cannot be found MVC 4
我正在研究Visual Studio,MVC。
我生成了一個ADO模型,用這個模型創建了一個新的控制器並改變了路由,但是我的控制器似乎是不可用的,即使我嘗試從另一個控制器重定向。
我的控制器:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Garnak.Models;
namespace Garnak.Views
{
public class leIndex : Controller
{
private garnakEntities db = new garnakEntities();
//
// GET: /leIndex/
public ActionResult Index()
{
return View(db.compteSet.ToList());
}
//
// GET: /leIndex/Details/5
public ActionResult Details(int id = 0)
{
compteSet compteset = db.compteSet.Find(id);
if (compteset == null)
{
return HttpNotFound();
}
return View(compteset);
}
//
// GET: /leIndex/Create
public ActionResult Create()
{
return View();
}
//
// POST: /leIndex/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(compteSet compteset)
{
if (ModelState.IsValid)
{
db.compteSet.Add(compteset);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(compteset);
}
//
// GET: /leIndex/Edit/5
public ActionResult Edit(int id = 0)
{
compteSet compteset = db.compteSet.Find(id);
if (compteset == null)
{
return HttpNotFound();
}
return View(compteset);
}
//
// POST: /leIndex/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(compteSet compteset)
{
if (ModelState.IsValid)
{
db.Entry(compteset).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(compteset);
}
//
// GET: /leIndex/Delete/5
public ActionResult Delete(int id = 0)
{
compteSet compteset = db.compteSet.Find(id);
if (compteset == null)
{
return HttpNotFound();
}
return View(compteset);
}
//
// POST: /leIndex/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
compteSet compteset = db.compteSet.Find(id);
db.compteSet.Remove(compteset);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
我的路線:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace Garnak
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "leIndex", action = "Index", id = UrlParameter.Optional }
);
}
}
}
任何想法為什么Visual Studio告訴我無法找到資源?
ASP.NET MVC
的控制器工廠遵循控制器應遵循的命名約定 - 默認情況下。 你可以通過創建自己的工廠來改變它,但是現在,改變
public class leIndex : Controller { ... }
至
public class leIndexController : Controller { ... }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.