adam3039
adam3039

Reputation: 1191

Multiple parameter route not matching

Can someone please explain to me why this route :

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

Does not match this action:

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

I've listed the route as the first one, so there is no route before it that is capturing it. Instead of it matching I'm just getting Search/Details?mlsId=...&propertyType=...

Upvotes: 0

Views: 42

Answers (1)

Brandon Gano
Brandon Gano

Reputation: 6710

The mls argument is the culprit. You should be able to fix it by assigning a default value to the mls argument:

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

Or defining a default value in the route:

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

Upvotes: 1

Related Questions