[英]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.