Route
リンクを達成するためにMVC3で新しいものを作成しようとしていますhttp://localhost/Product/1/abcxyz
:
routes.MapRoute(
"ProductIndex", // Route name
"{controller}/{id}/{name}", // URL with parameters
new { controller = "Product", action = "Index", id = UrlParameter.Optional, name = UrlParameter.Optional } // Parameter defaults
);
そして、私はRoute Link
このように使用しました:
<li>@Html.RouteLink("My Link", "ProductIndex", new { controller = "Product", id = 10, name = "abcxyz" })</li>
商品インデックス アクション:
public ViewResult Index(int id, string name)
{
var product = db.Product.Include(t => t.SubCategory).Where(s => s.SubID == id);
return View(product.ToList());
}
URL は期待どおりにレンダリングされます。しかし、それをクリックすると、メッセージ付きの 404 エラーが発生しました
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
アップデート
私はそれをRoute
上に置きDefault Route
、URLは正常に機能します。しかし、問題が発生しています。私のインデックスページはコントローラーのアクションをhttp://locahost
直接指していますが、代わりにコントローラーのアクションを指したいですIndex
Product
Index
Home