【发布时间】:2013-05-30 17:16:33
【问题描述】:
我正在尝试在MVC3中创建一个新的Route来实现链接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());
}
网址按我的预期呈现。但是当我点击它时,我收到了一个带有消息的 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 直接指向Product 控制器的Index 操作,但我希望它指向Home 控制器的Index 操作
【问题讨论】:
标签: asp.net-mvc-3