【发布时间】:2017-12-19 12:45:06
【问题描述】:
RoutePrefix 对我不起作用。
控制器
[RoutePrefix("example-name")]
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Title = "Home Page";
return View();
}
}
路由配置
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapMvcAttributeRoutes();
}
索引页面
@Html.ActionLink("click me", "index","example-name");
我已经完成了所有的基本步骤,但是我没有得到 404
找不到资源。
System.Web.Mvc.dll 的版本是 5.2.3.0
【问题讨论】:
-
请查看我的回复:我发现您的代码有问题...如果您为控件指定 RoutePrefix 属性,则需要为操作指定 Route 属性.....您尚未应用 [Route]在你的方法上
-
你能按照我的建议一步一步地尝试吗?一旦你改变了,你需要粘贴这个网址:localhost:8080/hometest/Index
标签: c# asp.net-mvc routing attributes