Example #1
0
        public static RouteValueDictionary GetRouteValueDictionary(this ControllerContext context, string methodName, bool usePostAction)
        {
            var routeValues    = new RouteValueDictionary();
            var controller     = context.Controller;
            var controllerName = MvcExpressionHelper.GetControllerName(controller.GetType());

            routeValues.Add(GridParameters.ControllerKey, controllerName);
            routeValues.Add(GridParameters.ActionKey, methodName);

            var        methods = controller.GetType().GetMethods().Where(m => m.Name == methodName);
            MethodInfo methodInfo;

            if (methods.Count() == 1)
            {
                methodInfo = methods.First();
            }
            else
            {
                methodInfo = methods.First(x => usePostAction
                                                    ? x.GetCustomAttributes(true).OfType <HttpPostAttribute>().Any()
                                                    : !x.GetCustomAttributes(true).OfType <HttpPostAttribute>().Any());
            }

            Requires <ArgumentException> .IsNotNull(methodInfo, string.Format("There's no method {0} in controller {1}", methodName, controllerName));

            foreach (var parameter in methodInfo.GetParameters())
            {
                routeValues.Add(parameter.Name, parameter.ParameterType.IsValueType ? Activator.CreateInstance(parameter.ParameterType) : null);
            }
            return(routeValues);
        }
Example #2
0
 private static string ItemNameForControllerType(Type controller)
 {
     return(ItemNameForElement(controller.Assembly.GetName().Name, MvcExpressionHelper.GetControllerName(controller)));
 }