ASP.NET MVC 3 服务器错误
本文关键字:服务器 错误 MVC NET ASP | 更新日期: 2023-09-27 18:34:43
我有以下控制器:
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);
}
}
和 2 个视图:
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>
路线
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 }
);
}
当我试图达到即 http://localhost:12952/Item/Description/2
我收到服务器错误:
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.
您的操作名称是"描述",而网址是"../描述/.."。它们不匹配。