public static ActionResult SecureAddRouteValues(this ActionResult result, System.Collections.Specialized.NameValueCollection nameValueCollection)
 {
     // Copy all the values from the NameValueCollection into the route dictionary
     if (nameValueCollection.AllKeys.Any(m => m == null))  //if it has a null, the CopyTo extension will crash!
     {
         var filtered = new System.Collections.Specialized.NameValueCollection(nameValueCollection);
         filtered.Remove(null);
         filtered.CopyTo(result.GetRouteValueDictionary());
     }
     else
     {
         nameValueCollection.CopyTo(result.GetRouteValueDictionary(), replaceEntries: true);
     }
     return(result);
 }
        private static Route CreateRoute(string url, ActionResult result, object defaults, object constraints, string[] namespaces)
        {
            // Start by adding the default values from the anonymous object (if any)
            var routeValues = new RouteValueDictionary(defaults);

            // Then add the Controller/SecureAction names and the parameters from the call
            foreach (var pair in result.GetRouteValueDictionary())
            {
                routeValues.Add(pair.Key, pair.Value);
            }

            var routeConstraints = new RouteValueDictionary(constraints);

            // Create and add the route
            var route = new Route(url, routeValues, routeConstraints, new MvcRouteHandler());

            route.DataTokens = new RouteValueDictionary();

            if (namespaces != null && namespaces.Length > 0)
            {
                route.DataTokens["Namespaces"] = namespaces;
            }

            return(route);
        }
        public static ActionResult AddRouteValue(this ActionResult result, string name, object value)
        {
            RouteValueDictionary routeValues = result.GetRouteValueDictionary();

            ModelUnbinderHelpers.AddRouteValues(routeValues, name, value);
            return(result);
        }
 public static string GetUrl(this HtmlHelper html, ActionResult actionResult)
 {
     if (actionResult == null) throw new ArgumentNullException("actionResult");
     RouteValueDictionary routeValueDictionary = actionResult.GetRouteValueDictionary();
     return UrlHelper.GenerateUrl(null, null, null, routeValueDictionary, html.RouteCollection,
                           html.ViewContext.RequestContext, false);
 }
Esempio n. 5
0
 public static string NavImageLink(this HtmlHelper helper, string linkText, string imageTag, ActionResult action)
 {
     var urlHelper = new UrlHelper(helper.ViewContext.RequestContext, helper.RouteCollection);
     var tagBuilder = new TagBuilder("a");
     tagBuilder.MergeAttribute("href", urlHelper.RouteUrl(action.GetRouteValueDictionary()));
     tagBuilder.InnerHtml = helper.ImgFor(imageTag) + linkText;
     return tagBuilder.ToString(TagRenderMode.Normal);
 }
        public static MvcHtmlString IsActive(this HtmlHelper helper, ActionResult action)
        {
            RouteValueDictionary dic = action.GetRouteValueDictionary();
            var actionName = dic["Action"].ToString();
            var controllerName = dic["Controller"].ToString();
            var currentAction = helper.ViewContext.RouteData.Values["Action"].ToString();
            var currentController = helper.ViewContext.RouteData.Values["Controller"].ToString();
            var rslt = string.Equals(actionName, currentAction, StringComparison.OrdinalIgnoreCase) && string.Equals(controllerName, currentController, StringComparison.OrdinalIgnoreCase);

            return rslt ? new MvcHtmlString(@" class=""active "" ") : new MvcHtmlString(string.Empty);
        }
        public static ActionResult SecureAddRouteValues(this ActionResult result, RouteValueDictionary routeValues)
        {
            RouteValueDictionary currentRouteValues = result.GetRouteValueDictionary();

            // Add all the extra values
            foreach (var pair in routeValues)
            {
                ModelUnbinderHelpers.AddRouteValues(currentRouteValues, pair.Key, pair.Value);
            }

            return(result);
        }
        /// <summary>
        /// If specific route can be found, return that route with the parameter tokens in route string.
        /// </summary>
        public static string JavaScriptReplaceableUrl(this UrlHelper urlHelper, ActionResult result)
        {
            var    rvd  = result.GetRouteValueDictionary();
            string area = string.Empty;
            object token;

            if (rvd.TryGetValue("area", out token))
            {
                area = token.ToString();
            }

            if (!rvd.TryGetValue("controller", out token))
            {
                throw new Exception("T4MVC JavascriptReplacableUrl could not locate controller in source dictionary");
            }
            string controller = token.ToString();

            if (!rvd.TryGetValue("SecureAction", out token))
            {
                throw new Exception("T4MVC JavascriptReplacableUrl could not locate SecureAction in source dictionary");
            }
            string SecureAction = token.ToString();

            // This matches the ActionResult to a specific route (so we can get the exact URL)
            string specificSecureActionUrl = RouteTable.Routes.OfType <Route>()
                                             .Where(r => r.DataTokens.CompareValue("area", area) &&
                                                    r.Defaults.CompareValue("controller", controller) &&
                                                    r.Defaults.CompareValue("SecureAction", SecureAction))
                                             .Select(r => r.Url)
                                             .FirstOrDefault();

            if (String.IsNullOrEmpty(specificSecureActionUrl))
            {
                return(urlHelper.RouteUrl(null, result.GetRouteValueDictionary()));
            }

            return(urlHelper.Content("~/" + specificSecureActionUrl));
        }
Esempio n. 9
0
        public static Route MapRoute(this RouteCollection routes, string name, string url, ActionResult result, object defaults) {
            // Start by adding the default values from the anonymous object (if any)
            var routeValues = new RouteValueDictionary(defaults);

            // Then add the Controller/Action names and the parameters from the call
            foreach (var pair in result.GetRouteValueDictionary()) {
                routeValues.Add(pair.Key, pair.Value);
            }

            // Create and add the route
            var route = new Route(url, routeValues, new MvcRouteHandler());
            routes.Add(name, route);
            return route;
        }
Esempio n. 10
0
 public static string Action(this UrlHelper urlHelper, ActionResult result, string protocol = null, string hostName = null)
 {
     return urlHelper.RouteUrl(null, result.GetRouteValueDictionary(), protocol ?? result.GetT4MVCResult().Protocol, hostName);
 }
Esempio n. 11
0
 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result) {
     return htmlHelper.RouteLink(linkText, result.GetRouteValueDictionary());
 }
Esempio n. 12
0
 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, IDictionary<string, object> htmlAttributes) {
     return htmlHelper.RouteLink(linkText, result.GetRouteValueDictionary(), htmlAttributes);
 }
Esempio n. 13
0
 public static MvcHtmlString SecureActionLink(this AjaxHelper ajaxHelper, string linkText, ActionResult result, AjaxOptions ajaxOptions)
 {
     return ajaxHelper.RouteLink(linkText, result.GetRouteValueDictionary(), ajaxOptions);
 }
Esempio n. 14
0
        /// <summary>
        /// If specific route can be found, return that route with the parameter tokens in route string.
        /// </summary>
        public static string JavaScriptReplaceableUrl(this UrlHelper urlHelper, ActionResult result)
        {
            var rvd = result.GetRouteValueDictionary();
            string area = string.Empty;
            object token;

            if (rvd.TryGetValue("area", out token))
                area = token.ToString();

            if (!rvd.TryGetValue("controller", out token))
                throw new Exception("T4MVC JavascriptReplacableUrl could not locate controller in source dictionary");
            string controller = token.ToString();

            if (!rvd.TryGetValue("SecureAction", out token))
                throw new Exception("T4MVC JavascriptReplacableUrl could not locate SecureAction in source dictionary");
            string SecureAction = token.ToString();

            // This matches the ActionResult to a specific route (so we can get the exact URL)
            string specificSecureActionUrl = RouteTable.Routes.OfType<Route>()
                .Where(r => r.DataTokens.CompareValue("area", area)
                    && r.Defaults.CompareValue("controller", controller)
                    && r.Defaults.CompareValue("SecureAction", SecureAction))
                .Select(r => r.Url)
                .FirstOrDefault();

            if (String.IsNullOrEmpty(specificSecureActionUrl))
            {
                return urlHelper.RouteUrl(null, result.GetRouteValueDictionary());
            }

            return urlHelper.Content("~/" + specificSecureActionUrl);
        }
        public static string ResolveUrl(this ControllerContext context, ActionResult result)
        {
            var logger = ObjectFactory.GetInstance<Logger>();

            if (context == null)
            {
                logger.Error("[Extensions].[ControllerContextExtensions].[ResolveUrl(ControllerContext, ActionResult)] throwing exception ([context] == null).");
                throw new ArgumentNullException("context");
            }

            if (result == null)
            {
                logger.Error("[Extensions].[ControllerContextExtensions].[ResolveUrl(ControllerContext, ActionResult)] throwing exception ([result] == null).");
                throw new ArgumentNullException("result");
            }

            return RouteTable.Routes.GetVirtualPath(context.RequestContext, result.GetRouteValueDictionary()).VirtualPath;
        }
Esempio n. 16
0
 public static MvcHtmlString SecureActionLink(this AjaxHelper ajaxHelper, string linkText, ActionResult result, AjaxOptions ajaxOptions)
 {
     return(ajaxHelper.RouteLink(linkText, result.GetRouteValueDictionary(), ajaxOptions));
 }
Esempio n. 17
0
 public static string RouteUrl(this UrlHelper urlHelper, string routeName, ActionResult result, string protocol, string hostName)
 {
     return(urlHelper.RouteUrl(routeName, result.GetRouteValueDictionary(), protocol ?? result.GetT4MVCResult().Protocol, hostName));
 }
Esempio n. 18
0
 public static string SecureAction(this UrlHelper urlHelper, ActionResult result, string protocol = null, string hostName = null)
 {
     return(urlHelper.RouteUrl(null, result.GetRouteValueDictionary(), protocol ?? result.GetT4MVCResult().Protocol, hostName));
 }
Esempio n. 19
0
 public static MvcForm SecureBeginRouteForm(this HtmlHelper htmlHelper, string routeName, ActionResult result, FormMethod method, IDictionary <string, object> htmlAttributes)
 {
     return(htmlHelper.BeginRouteForm(routeName, result.GetRouteValueDictionary(), method, htmlAttributes));
 }
Esempio n. 20
0
 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, object htmlAttributes, string protocol = null, string hostName = null, string fragment = null)
 {
     return(htmlHelper.RouteLink(linkText, null, protocol ?? result.GetT4MVCResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
 }
Esempio n. 21
0
 public static TransferToRouteResult TransferToAction(this Controller controller, ActionResult result)
 {
     return new TransferToRouteResult(result.GetRouteValueDictionary());
 }
Esempio n. 22
0
 public static MvcHtmlString SecureActionLink(this AjaxHelper ajaxHelper, string linkText, ActionResult result, AjaxOptions ajaxOptions, object htmlAttributes)
 {
     return(ajaxHelper.RouteLink(linkText, result.GetRouteValueDictionary(), ajaxOptions, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
 }
Esempio n. 23
0
 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result)
 {
     return(htmlHelper.RouteLink(linkText, result.GetRouteValueDictionary()));
 }
Esempio n. 24
0
 public static MvcHtmlString RouteLink(this AjaxHelper ajaxHelper, string linkText, string routeName, ActionResult result, AjaxOptions ajaxOptions, IDictionary <string, object> htmlAttributes)
 {
     return(ajaxHelper.RouteLink(linkText, routeName, result.GetRouteValueDictionary(), ajaxOptions, htmlAttributes));
 }
Esempio n. 25
0
 public static string ActionLink(this AjaxHelper ajaxHelper, string linkText, ActionResult result, AjaxOptions ajaxOptions, object htmlAttributes) {
     return ajaxHelper.RouteLink(linkText, result.GetRouteValueDictionary(), ajaxOptions, new RouteValueDictionary(htmlAttributes));
 }
Esempio n. 26
0
 public static MvcForm SecureBeginRouteForm(this AjaxHelper ajaxHelper, string routeName, ActionResult result, AjaxOptions ajaxOptions, IDictionary <string, object> htmlAttributes)
 {
     return(ajaxHelper.BeginRouteForm(routeName, result.GetRouteValueDictionary(), ajaxOptions, htmlAttributes));
 }
Esempio n. 27
0
 public static MvcForm SecureBeginRouteForm(this HtmlHelper htmlHelper, string routeName, ActionResult result, FormMethod method, IDictionary<string, object> htmlAttributes)
 {
     return htmlHelper.BeginRouteForm(routeName, result.GetRouteValueDictionary(), method, htmlAttributes);
 }
Esempio n. 28
0
 public static ActionResult AddRouteValues(this ActionResult result, System.Collections.Specialized.NameValueCollection nameValueCollection)
 {
     // Copy all the values from the NameValueCollection into the route dictionary
     nameValueCollection.CopyTo(result.GetRouteValueDictionary());
     return(result);
 }
Esempio n. 29
0
 public static string RouteUrl(this UrlHelper urlHelper, string routeName, ActionResult result, string protocol, string hostName)
 {
     return urlHelper.RouteUrl(routeName, result.GetRouteValueDictionary(), protocol ?? result.GetT4MVCResult().Protocol, hostName);
 }
Esempio n. 30
0
 public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, ActionResult result, AjaxOptions ajaxOptions, object htmlAttributes)
 {
     return ajaxHelper.RouteLink(linkText, result.GetRouteValueDictionary(), ajaxOptions, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
 }
Esempio n. 31
0
 public static MvcForm SecureBeginRouteForm(this AjaxHelper ajaxHelper, string routeName, ActionResult result, AjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes)
 {
     return ajaxHelper.BeginRouteForm(routeName, result.GetRouteValueDictionary(), ajaxOptions, htmlAttributes);
 }
Esempio n. 32
0
        private static Route CreateRoute(string url, ActionResult result, object defaults, object constraints, string[] namespaces)
        {
            // Start by adding the default values from the anonymous object (if any)
            var routeValues = new RouteValueDictionary(defaults);

            // Then add the Controller/Action names and the parameters from the call
            foreach (var pair in result.GetRouteValueDictionary())
            {
                routeValues.Add(pair.Key, pair.Value);
            }

            var routeConstraints = new RouteValueDictionary(constraints);

            // Create and add the route
            var route = new Route(url, routeValues, routeConstraints, new MvcRouteHandler());

            route.DataTokens = new RouteValueDictionary();

            if (namespaces != null && namespaces.Length > 0)
            {
                route.DataTokens["Namespaces"] = namespaces;
            }

            return route;
        }
Esempio n. 33
0
 public static string Action(this UrlHelper urlHelper, ActionResult result) {
     return urlHelper.RouteUrl(null, result.GetRouteValueDictionary());
 }
Esempio n. 34
0
 public static string Action(this UrlHelper urlHelper, ActionResult result)
 {
     return(urlHelper.RouteUrl(null, result.GetRouteValueDictionary()));
 }
Esempio n. 35
0
 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, object htmlAttributes, string protocol = null, string hostName = null, string fragment = null) {
     return htmlHelper.RouteLink(linkText, null, protocol ?? result.GetT4MVCResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
 }
Esempio n. 36
0
 public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, ActionResult result, AjaxOptions ajaxOptions, object htmlAttributes)
 {
     return(ajaxHelper.RouteLink(linkText, result.GetRouteValueDictionary(), ajaxOptions, new RouteValueDictionary(htmlAttributes)));
 }
Esempio n. 37
0
 public static string ActionAbsolute(this UrlHelper urlHelper, ActionResult result)
 {
     return string.Format("{0}{1}",urlHelper.RequestContext.HttpContext.Request.Url.GetLeftPart(UriPartial.Authority),
         urlHelper.RouteUrl(result.GetRouteValueDictionary()));
 }
Esempio n. 38
0
 public static string ActionAbsolute(this UrlHelper urlHelper, ActionResult result)
 {
     return(string.Format("{0}{1}", urlHelper.RequestContext.HttpContext.Request.Url.GetLeftPart(UriPartial.Authority),
                          urlHelper.RouteUrl(result.GetRouteValueDictionary())));
 }
Esempio n. 39
0
 public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, ActionResult result, AjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes)
 {
     return ajaxHelper.RouteLink(linkText, result.GetRouteValueDictionary(), ajaxOptions, htmlAttributes);
 }
Esempio n. 40
0
 public static MvcHtmlString SecureActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, IDictionary <string, object> htmlAttributes, string protocol, string hostName, string fragment)
 {
     return(htmlHelper.RouteLink(linkText, null, protocol ?? result.GetT4MVCResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), htmlAttributes));
 }
Esempio n. 41
0
 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, IDictionary<string, object> htmlAttributes, string protocol, string hostName, string fragment)
 {
     return htmlHelper.RouteLink(linkText, null, protocol ?? result.GetT4MVCResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), htmlAttributes);
 }
Esempio n. 42
0
 public static string ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, IDictionary <string, object> htmlAttributes)
 {
     return(htmlHelper.RouteLink(linkText, result.GetRouteValueDictionary(), htmlAttributes));
 }