private static IDictionary BuildUrlParameters(UrlHelper urlHelper, ActionMethodModel actionModel) { var urlParams = DictHelper .CreateN("Area", actionModel.Descriptor.Area) .N("Controller", actionModel.Descriptor.Name) .N("Action", actionModel.MethodInfo.Name); var queryParams = actionModel.GetParameterDictionary(); if (queryParams != null && queryParams.Count > 0) { string queryString = urlHelper.BuildQueryString(queryParams); if (!string.IsNullOrEmpty(queryString)) { urlParams.Add("QueryString", queryString); } // What was i thinking when i wrote this...? foreach (var queryKey in queryParams.Keys) { if (!urlParams.Contains(queryKey)) { urlParams.Add(queryKey, queryParams[queryKey]); } } } return(urlParams); }
public static string TypedFor <TController>( this UrlHelper self, Expression <Action <TController> > action) where TController : IController { AssertArguments(self, action); ActionMethodModel model = CreateModel(action); IDictionary urlParams = BuildUrlParameters(self, model); return(self.For(urlParams)); }
public static string TypedLink <TController>( this UrlHelper self, string innerContent, Expression <Action <TController> > action, IDictionary anchorAttributes) where TController : IController { AssertArguments(self, action); ActionMethodModel model = CreateModel(action); IDictionary urlParams = BuildUrlParameters(self, model); return(self.Link(innerContent, urlParams, anchorAttributes)); }
public static void RedirectToAction <TController>( this TController self, bool useRouting, Expression <Action <TController> > action) where TController : Controller { AssertArguments(self, action); ActionMethodModel model = CreateModel(action); IRedirectInvoker redirecter = new SameControllerRedirectInvoker(self) { UseRouting = useRouting }; redirecter.Redirect(self, model); }
/// <summary> /// Performs a strongly typed redirect to an action of the <typeparamref name="TController"/>. /// <para /> /// This must be a lamda in the form of <c>c => c.Action(optional, action, parameters)</c>, /// where the action parameters can be anything you want (variable, property, method call etc.) /// as long as they return the right parameter and the lambda function will compile. /// </summary> /// <typeparam name="TController">The type of the controller that has the action.</typeparam> /// <param name="self">The object that supports redirecting.</param> /// <param name="useRouting">If true, uses routing.</param> /// <param name="action">An expression that respresents the redirect in the form of a lambda function call.</param> public static void Redirect <TController>( this IRedirectSupport self, bool useRouting, Expression <Action <TController> > action) where TController : IController { AssertArguments(self, action); ActionMethodModel model = CreateModel(action); var redirecter = new ResponseRedirectInvoker { UseRouting = useRouting }; redirecter.Redirect(self, model); }
private static ActionMethodModel CreateModel <TController>(Expression <Action <TController> > action) where TController : IController { // TODO: Windsor integration? IActionParametersBuilder paramBuilder = new ExcludeNullOrEmptyParametersBuilder( new ARAwareActionParametersBuilder( new DefaultActionParametersBuilder())); IActionMethodBuilder actionBuilder = new DefaultActionMethodBuilder(paramBuilder); ActionMethodModel model = actionBuilder.BuildAction(action); return(model); }
public virtual void Redirect(IRedirectSupport redirecter, ActionMethodModel action) { Redirect(redirecter, action.Area, action.Controller, action.Action, action.GetParameterDictionary()); }