Fix for issue #339

This commit is contained in:
Ryan Nowak 2014-05-09 16:16:13 -07:00
parent 00c30791ea
commit 88be38a506
1 changed files with 19 additions and 16 deletions

View File

@ -34,6 +34,24 @@ namespace Microsoft.AspNet.Mvc
var allDescriptors = GetActions();
var matching = allDescriptors.Where(ad => Match(ad, context)).ToList();
var matchesWithConstraints = new List<ActionDescriptor>();
foreach (var match in matching)
{
if (match.DynamicConstraints != null && match.DynamicConstraints.Any() ||
match.MethodConstraints != null && match.MethodConstraints.Any())
{
matchesWithConstraints.Add(match);
}
}
// If any action that's applicable has constraints, this is considered better than
// an action without.
if (matchesWithConstraints.Any())
{
matching = matchesWithConstraints;
}
if (matching.Count == 0)
{
return null;
@ -96,12 +114,6 @@ namespace Microsoft.AspNet.Mvc
}
}
if (action.DynamicConstraints != null && action.DynamicConstraints.Any() ||
action.MethodConstraints != null && action.MethodConstraints.Any())
{
candidate.HasNonRouteConstraints = true;
}
if (isApplicable)
{
applicableCandiates.Add(candidate);
@ -113,14 +125,8 @@ namespace Microsoft.AspNet.Mvc
return null;
}
var bestByConstraints =
var mostParametersSatisfied =
applicableCandiates
.GroupBy(c => c.HasNonRouteConstraints ? 1 : 0)
.OrderByDescending(g => g.Key)
.First();
var mostParametersSatisfied =
bestByConstraints
.GroupBy(c => c.FoundParameters)
.OrderByDescending(g => g.Key)
.First();
@ -347,9 +353,6 @@ namespace Microsoft.AspNet.Mvc
{
public ActionDescriptor Action { get; set; }
// Actions with HTTP method constraints or dynamic constraints are better than those without.
public bool HasNonRouteConstraints { get; set; }
public int FoundParameters { get; set; }
public int FoundOptionalParameters { get; set; }