62,272
社区成员
发帖
与我相关
我的任务
分享
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] {""}
);
你也可以都不指定参数名,像下面这样写:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] {""}
);
C#中有命名参数和可选参数之分,另外从错误提示已经说明了,命名参数只能放置最后,如果你前面设置了命名参数,则后面的所有参数都应该指定参数,否则就会有你上面的错误,如果你最后一个指定命名参数的,前面不指定是不会出错的。例如下面:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] {""}
);
这个是可以的,相信我解释的够详细了吧。
关于C#基础的建议你可以看看这本书:
http://item.jd.com/11657095.html