diff --git a/samples/MvcSample/SimplePocoController.cs b/samples/MvcSample/SimplePocoController.cs new file mode 100644 index 0000000000..d31e32e9b1 --- /dev/null +++ b/samples/MvcSample/SimplePocoController.cs @@ -0,0 +1,10 @@ +namespace MvcSample +{ + public class SimplePocoController + { + public string Index() + { + return "Hello world"; + } + } +} diff --git a/src/Microsoft.AspNet.Mvc/ControllerActionInvoker.cs b/src/Microsoft.AspNet.Mvc/ControllerActionInvoker.cs index 575d6a2fbe..a7b14a4483 100644 --- a/src/Microsoft.AspNet.Mvc/ControllerActionInvoker.cs +++ b/src/Microsoft.AspNet.Mvc/ControllerActionInvoker.cs @@ -45,12 +45,14 @@ namespace Microsoft.AspNet.Mvc if (method == null) { - throw new InvalidOperationException(String.Format("Could not find action method '{0}'", _descriptor.ActionName)); + actionResult = new HttpStatusCodeResult(404); } + else + { + object actionReturnValue = method.Invoke(controller, null); - object actionReturnValue = method.Invoke(controller, null); - - actionResult = _actionResultFactory.CreateActionResult(method.ReturnType, actionReturnValue, _requestContext); + actionResult = _actionResultFactory.CreateActionResult(method.ReturnType, actionReturnValue, _requestContext); + } } // TODO: This will probably move out once we got filters diff --git a/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs b/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs index 591b489712..c284196376 100644 --- a/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs +++ b/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs @@ -31,7 +31,21 @@ namespace Microsoft.AspNet.Mvc { try { - return ActivatorUtilities.CreateInstance(_serviceProvider, descriptor.ControllerType); + var controller = ActivatorUtilities.CreateInstance(_serviceProvider, descriptor.ControllerType); + + // TODO: How do we feed the controller with context (need DI improvements) + var contextProperty = +#if NET45 + descriptor.ControllerType.GetProperty("Context"); +#else + descriptor.ControllerType.GetRuntimeProperty("Context"); +#endif + if (contextProperty != null) + { + contextProperty.SetMethod.Invoke(controller, new [] { context }); + } + + return controller; } catch (ReflectionTypeLoadException) {