Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 找不到资源MVC 4_C#_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

C# 找不到资源MVC 4

C# 找不到资源MVC 4,c#,asp.net-mvc,asp.net-mvc-4,C#,Asp.net Mvc,Asp.net 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

我在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告诉我找不到ressource吗?

ASP.NET MVC
的控制器工厂遵循一个命名约定,默认情况下,控制器应遵循该命名约定。你可以通过创建自己的工厂来改变它,但现在,改变

public class leIndex : Controller { ... }


您是否针对每个操作创建了视图?是否应该是
公共类leIndexController:Controller
?是的,visual studio使用这些视图生成了控制器,因此它在视图中创建了一个名为“leIndex”的目录,其中包含5个文件:索引、创建、编辑、详细信息和删除。-快速阅读ASP.NET MVC控制器。我仍然坚持要你重新命名你的班级。
public class leIndexController : Controller { ... }