Asp.net mvc 带可选参数的mvc属性路由

Asp.net mvc 带可选参数的mvc属性路由,asp.net-mvc,routes,custom-attributes,Asp.net Mvc,Routes,Custom Attributes,我得到了以下属性集 [Route("{country}/{state}/{city}/listing/{name?}/{address}/{id}", Name = "ViewListing")] public ActionResult Index() { ... } 下面的url工作正常 http://localhost:16949/ca/on/london/listing/something/1830-avalon-street/d46fc94f-9

我得到了以下属性集

    [Route("{country}/{state}/{city}/listing/{name?}/{address}/{id}", Name = "ViewListing")]
    public ActionResult Index()
    {
    ...
    }
下面的url工作正常

http://localhost:16949/ca/on/london/listing/something/1830-avalon-street/d46fc94f-9a90-460a-b18f-7443db3c1897
然而,下面给出了404,即使name参数设置为可选

http://localhost:16949/ca/on/london/listing/1830-avalon-street/d46fc94f-9a90-460a-b18f-7443db3c1897
我还定义了其他路由,这些路由具有相同数量的参数和不同的结构,并且这些路由也不会触发(它们也不应该触发),为清楚起见,这里是其他路由

CITY
{country}/{state}/{city}
{country}/{state}/{city}/{type}
{country}/{state}/{city}/bedrooms/{parameters}
{country}/{state}/{city}/{type}/bedrooms/{parameters}
{country}/{state}/{city}/area/{area}
{country}/{state}/{city}/area/{area}/bedrooms/{parameters}

选项route参数应至少为。在您的情况下,当您没有传递{name}时,路由将不匹配“{country}/{state}/{city}/listing/{address}/{id}”。然后不匹配第二个url,所以它会给你404