I have the following controller:
public class ItemController : Controller
{
private SomeDbEntities _db= new SomeDbEntities ();
//
// GET: /Item/
public ActionResult Index()
{
var items = _db.Items.ToList();
return View(items);
}
public ActionResult Decription(int id)
{
var item = _db.Items.Single(a => a.ItemID == id);
return View(item);
}
}
and 2 views:
Index.cshmtl
@model IEnumerable<Web.Models.Item>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<ul>
@foreach (var item in Model)
{
<li>@Html.ActionLink(item.Name, "Description", new { id = item.ItemID})</li>
}
Description.cshtml
@model Web.Models.Item
@{
ViewBag.Title = "Decription";
}
<h2>Decription</h2>
<p>@Model.Description</p>
Route
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Item", action = "Index", id = UrlParameter.Optional }
);
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
And when i try to reach i.e. http://localhost:12952/Item/Description/2 i am getting Server error:
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.
Your action name is “Decription” while the url is “../Description/..”. They don’t match.