I am working at an ASp.net mvc 3 project and
I keep getting this error and can find any help to solve the problem
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: /RoomType
But I have The RoomType controller and in my Global.asax I have:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
null, // we don't need to specify a name
"Page{page}",
new { Controller = "Room", action = "List" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Room", action = "List", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
null, // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Room", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
null, // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "RoomType", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Here is my RoomTypeController :
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Objects;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication4.Models;
namespace MvcApplication4.Controllers
{
public class RoomTypeController : Controller
{
private hotelEntities db = new hotelEntities();
//
// GET: /RoomType/
public ViewResult Index(int start = 0, int itemsPerPage = 20, string orderBy = "RoomType_ID", bool desc = false)
{
ViewBag.Count = db.Room_Type.Count();
ViewBag.Start = start;
ViewBag.ItemsPerPage = itemsPerPage;
ViewBag.OrderBy = orderBy;
ViewBag.Desc = desc;
return View();
}
//
// GET: /RoomType/GridData/?start=0&itemsPerPage=20&orderBy=RoomType_ID&desc=true
public ActionResult GridData(int start = 0, int itemsPerPage = 20, string orderBy = "RoomType_ID", bool desc = false)
{
Response.AppendHeader("X-Total-Row-Count", db.Room_Type.Count().ToString());
ObjectQuery<Room_Type> room_type = (db as IObjectContextAdapter).ObjectContext.CreateObjectSet<Room_Type>();
room_type = room_type.OrderBy("it." + orderBy + (desc ? " desc" : ""));
return PartialView(room_type.Skip(start).Take(itemsPerPage));
}
//
// GET: /Default5/RowData/5
public ActionResult RowData(int id)
{
Room_Type room_type = db.Room_Type.Find(id);
return PartialView("GridData", new Room_Type[] { room_type });
}
//
// GET: /RoomType/Create
public ActionResult Create()
{
return PartialView("Edit");
}
//
// POST: /RoomType/Create
[HttpPost]
public ActionResult Create(Room_Type room_type)
{
if (ModelState.IsValid)
{
db.Room_Type.Add(room_type);
db.SaveChanges();
return PartialView("GridData", new Room_Type[] { room_type });
}
return PartialView("Edit", room_type);
}
//
// GET: /RoomType/Edit/5
public ActionResult Edit(int id)
{
Room_Type room_type = db.Room_Type.Find(id);
return PartialView(room_type);
}
//
// POST: /RoomType/Edit/5
[HttpPost]
public ActionResult Edit(Room_Type room_type)
{
if (ModelState.IsValid)
{
db.Entry(room_type).State = EntityState.Modified;
db.SaveChanges();
return PartialView("GridData", new Room_Type[] { room_type });
}
return PartialView(room_type);
}
//
// POST: /RoomType/Delete/5
[HttpPost]
public void Delete(int id)
{
Room_Type room_type = db.Room_Type.Find(id);
db.Room_Type.Remove(room_type);
db.SaveChanges();
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
Make sure that your controller class is called
RoomTypeController(and notRoomType, and notRoomController) and that it contains anIndexaction: