Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# URL路由需要/Home/Page?Page=1而不是/Home/Page/1_C#_Asp.net Mvc_Url_Seo_Maproute - Fatal编程技术网

C# URL路由需要/Home/Page?Page=1而不是/Home/Page/1

C# URL路由需要/Home/Page?Page=1而不是/Home/Page/1,c#,asp.net-mvc,url,seo,maproute,C#,Asp.net Mvc,Url,Seo,Maproute,我正在尝试构建我的ASP.NETMVC4.5项目,以使用搜索引擎友好的URL。我正在使用以下路线图 routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}/{title}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, title = UrlParameter.Optiona

我正在尝试构建我的ASP.NETMVC4.5项目,以使用搜索引擎友好的URL。我正在使用以下路线图

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}/{title}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, title = UrlParameter.Optional }
);
目的是让我可以创建如下URL:

<a href="@Url.Action("Page", "Home", new { page = 1 })">1</a>
Mysite.com/Home/Page/1/this-title-bit-is-just-for-show

但它失败了,我不得不使用如下URL:

<a href="@Url.Action("Page", "Home", new { page = 1 })">1</a>
Mysite.com/Home/Page?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>

有人能告诉我哪里出了问题吗?

而不是

<a href="@Url.Action("Page", "Home", new { page = 1 })">1</a>
而不是

<a href="@Url.Action("Page", "Home", new { page = 1 })">1</a>

将方法更改为
public ActionResult Page(int-id)
或将路由更改为
url:“{controller}/{action}/{Page}/{title}”,
,注意只有最后一个参数可以标记为
urlparmeter。可选的
uh。。。你在问一个关于主题的问题?那一定是错的。不知何故。将方法更改为
public ActionResult Page(int-id)
或将路由更改为
url:“{controller}/{action}/{Page}/{title}”,
,注意只有最后一个参数可以标记为
urlparmeter。可选的
uh。。。你在问一个关于主题的问题?那一定是错的。不知怎么的。谢谢你的帮助,这个解决了:)谢谢你的帮助,这个解决了:)