有人可以向我解释为什么这条路线:
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 = ...&amp; propertyType = ...
答案 0 :(得分:1)
mls
参数是罪魁祸首。您应该能够通过为mls
参数指定默认值来修复它:
public async Task<IActionResult> Details(... string mls = "something")
或者在路线中定义默认值:
new {controller= "Search", action="Details", mls="something"}