我正在尝试构建我的ASP.NET MVC 4.5项目来使用搜索引擎友好的URL。我正在使用下面的路径映射。
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}/{title}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, title = UrlParameter.Optional }
);这样我就可以创建这样的URL:
Mysite.com/Home/Page/1/this-title-bit-is-just-for-show
但是它失败了,我不得不使用这样的URL:
Mysite.com/Home/page=1
如果有关系,此链接所指向的主计长操作如下:
public ActionResult Page(int page)
{
PostModel pm = new PostModel(page);
return View(pm);
}我正在生成这样的URL:
<a href="@Url.Action("Page", "Home", new { page = 1 })">1</a>有人能告诉我哪里出了问题吗?
发布于 2016-02-18 03:48:47
而不是
<a href="@Url.Action("Page", "Home", new { page = 1 })">1</a>使用
<a href="@Url.Action("Page", "Home", new { id = 1 })">1</a> //instead of page use id here和改变行动方法如下:-
public ActionResult Page(int id) //instead of page use id here
{
PostModel pm = new PostModel(id);
return View(pm);
}https://stackoverflow.com/questions/35472431
复制相似问题