2016-09-11 114 views
0

可有人請向我解釋爲什麼這條線路:多參數的路由不匹配

routes.MapRoute(
    "ListingDetails", 
    "{city}-{propertyType}-for-sale-MLS-{mlsId}", 
    new {controller= "Search", action="Details"} 
    ); 

不匹配這個動作:

public async Task<IActionResult> Details(int mlsId, string city, string propertyType, string mls) 
     { 
      var listing = _listingService.GetListingByMlsId(mlsId); 
      return View(listing); 
     } 

我列爲第一個途徑,所以捕捉它之前沒有任何路線。而不是匹配我剛剛得到搜索/詳細信息?mlsId = ... & propertyType = ...

回答

1

mls參數是罪魁禍首。您應該能夠通過指定一個默認值到mls參數來解決它:

public async Task<IActionResult> Details(... string mls = "something") 

或者在路由定義了默認值:

new {controller= "Search", action="Details", mls="something"}