From b9dbb6fe57dfc5e335783a301aea1f76e3830048 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Fri, 9 May 2014 17:45:45 -0700 Subject: [PATCH] Fixing action selection with complex types - MVC scenarios with more than one parameter are broken right now --- samples/MvcSample.Web/OverloadController.cs | 18 ++++++++++++++++++ .../DefaultActionSelector.cs | 10 ++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/samples/MvcSample.Web/OverloadController.cs b/samples/MvcSample.Web/OverloadController.cs index 8b454eb0cf..aadfd004c8 100644 --- a/samples/MvcSample.Web/OverloadController.cs +++ b/samples/MvcSample.Web/OverloadController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNet.Mvc; +using MvcSample.Web.Models; namespace MvcSample.Web { @@ -26,5 +27,22 @@ namespace MvcSample.Web { return _result.Content("Get(id, name)", null, null); } + + public ActionResult WithUser() + { + return _result.Content("WithUser()", null, null); + } + + // Called for all posts regardless of values provided + [HttpPost] + public ActionResult WithUser(User user) + { + return _result.Content("WithUser(User)", null, null); + } + + public ActionResult WithUser(int projectId, User user) + { + return _result.Content("WithUser(int, User)", null, null); + } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/DefaultActionSelector.cs b/src/Microsoft.AspNet.Mvc.Core/DefaultActionSelector.cs index e9d7d228f9..8016e1092d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/DefaultActionSelector.cs +++ b/src/Microsoft.AspNet.Mvc.Core/DefaultActionSelector.cs @@ -7,6 +7,7 @@ using System.Diagnostics.Contracts; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Core; +using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Routing; using Microsoft.Framework.DependencyInjection; @@ -56,10 +57,6 @@ namespace Microsoft.AspNet.Mvc { return null; } - else if (matching.Count == 1) - { - return matching[0]; - } else { return await SelectBestCandidate(context, matching); @@ -99,6 +96,11 @@ namespace Microsoft.AspNet.Mvc foreach (var parameter in action.Parameters.Where(p => p.ParameterBindingInfo != null)) { + if (!ValueProviderResult.CanConvertFromString(parameter.ParameterBindingInfo.ParameterType)) + { + continue; + } + if (await actionBindingContext.ValueProvider.ContainsPrefixAsync(parameter.ParameterBindingInfo.Prefix)) { candidate.FoundParameters++;