Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
Asp.net mvc 3 mvc3中丑陋的url如何使其看起来好看?_Asp.net Mvc 3_Url_Maproute - Fatal编程技术网

Asp.net mvc 3 mvc3中丑陋的url如何使其看起来好看?

Asp.net mvc 3 mvc3中丑陋的url如何使其看起来好看?,asp.net-mvc-3,url,maproute,Asp.net Mvc 3,Url,Maproute,在我的应用程序中的Ideascontroller中有一个操作: public ViewResult NewIdeas(int numberOfPage = 1) 该操作“生成”url,如下所示: /Ideas/NewIdeas/?numberOfPage=1 很难看,应该是: /Ideas/NewIdeas/1 我知道新的MapRoute可能会解决这个问题,但它应该是什么样子呢? 谢谢您的帮助。您应该在global.asax中添加一条新路线: routes.MapRoute(

在我的应用程序中的
Ideas
controller中有一个操作:

public ViewResult NewIdeas(int numberOfPage = 1)
该操作“生成”url,如下所示:

/Ideas/NewIdeas/?numberOfPage=1
很难看,应该是:

/Ideas/NewIdeas/1
我知道新的MapRoute可能会解决这个问题,但它应该是什么样子呢?
谢谢您的帮助。

您应该在global.asax中添加一条新路线:

  routes.MapRoute(
      "NewIdeas", // Route name
      "Ideas/NewIdeas/{numberOfPage}", // URL with parameters
      new { controller = "Ideas", action = "NewIdeas", numberOfPage= UrlParameter.Optional } // Parameter defaults
  );