当我进入Store时,会显示找不到/ Store URL的错误(HTTP 404)。哪里可能是问题?也许我在某处输错了?
控制器操作是:
GET: /Store/
public ActionResult Index()
{
var genres = storeDb.Genres.ToList();
return View(genres);
}
的global.asax.cs:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");`
routes.MapRoute(
"Default", // Имя маршрута
"{controller}/{action}/{id}", // URL-адрес с параметрами
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
商店/索引视图如下所示:
@model IEnumerable<MvcApplication1.Models.Genre>
@{
ViewBag.Title = "Store";
}
<h3>Browse Genres</h3>
<p>
Select from @Model.Count() genres:</p>
<ul>
@foreach (var genre in Model)
{
<li>@Html.ActionLink(genre.Name, "Browse", new { genre = genre.Name })</li>
}
</ul>
答案 0 :(得分:-1)
好吧,我决定重新启动整个项目,然后一切正常。