Fix for issue #339
This commit is contained in:
parent
00c30791ea
commit
88be38a506
|
|
@ -34,6 +34,24 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var allDescriptors = GetActions();
|
var allDescriptors = GetActions();
|
||||||
|
|
||||||
var matching = allDescriptors.Where(ad => Match(ad, context)).ToList();
|
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)
|
if (matching.Count == 0)
|
||||||
{
|
{
|
||||||
return null;
|
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)
|
if (isApplicable)
|
||||||
{
|
{
|
||||||
applicableCandiates.Add(candidate);
|
applicableCandiates.Add(candidate);
|
||||||
|
|
@ -113,14 +125,8 @@ namespace Microsoft.AspNet.Mvc
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bestByConstraints =
|
var mostParametersSatisfied =
|
||||||
applicableCandiates
|
applicableCandiates
|
||||||
.GroupBy(c => c.HasNonRouteConstraints ? 1 : 0)
|
|
||||||
.OrderByDescending(g => g.Key)
|
|
||||||
.First();
|
|
||||||
|
|
||||||
var mostParametersSatisfied =
|
|
||||||
bestByConstraints
|
|
||||||
.GroupBy(c => c.FoundParameters)
|
.GroupBy(c => c.FoundParameters)
|
||||||
.OrderByDescending(g => g.Key)
|
.OrderByDescending(g => g.Key)
|
||||||
.First();
|
.First();
|
||||||
|
|
@ -347,9 +353,6 @@ namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
public ActionDescriptor Action { get; set; }
|
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 FoundParameters { get; set; }
|
||||||
|
|
||||||
public int FoundOptionalParameters { get; set; }
|
public int FoundOptionalParameters { get; set; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue