Esempio n. 1
0
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (context.IsChildAction)
            {
                throw new InvalidOperationException("MvcResources.RedirectAction_CannotRedirectInChildAction");
            }
            IDynamicNode node;
            var          value = UrlHelperEx.GenerateUrl(out node, RouteName, null, null, RouteValues, Routes, context.RequestContext, false);

            if (string.IsNullOrEmpty(value))
            {
                throw new InvalidOperationException("MvcResources.Common_NoRouteMatched");
            }
            context.Controller.TempData.Keep();
#if CLR4
            if (Permanent)
            {
                context.HttpContext.Response.RedirectPermanent(value, false);
            }
            else
            {
                context.HttpContext.Response.Redirect(value, false);
            }
#else
            context.HttpContext.Response.Redirect(value, false);
#endif
        }
Esempio n. 2
0
        private static string GenerateLinkInternal(RequestContext requestContext, RouteCollection routeCollection, Func <IDynamicNode, string> linkText, string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary <string, object> htmlAttributes, bool includeImplicitMvcValues)
        {
            IDynamicNode node;
            var          text = UrlHelperEx.GenerateUrl(out node, routeName, actionName, controllerName, protocol, hostName, fragment, routeValues, routeCollection, requestContext, includeImplicitMvcValues);

            if (node == null)
            {
                throw new InvalidOperationException("!Node");
            }
            var nodeAsLinkText = (linkText == null ? node.Title : linkText(node));
            var b = new TagBuilder("a");

            b.InnerHtml = (!string.IsNullOrEmpty(nodeAsLinkText) ? HttpUtility.HtmlEncode(nodeAsLinkText) : string.Empty);
            b.MergeAttributes <string, object>(htmlAttributes);
            b.MergeAttribute("href", text);
            return(b.ToString(TagRenderMode.Normal));
        }
 public static string ActionEx(this UrlHelper urlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, string protocol, string hostName)
 {
     IDynamicNode node; return(UrlHelperEx.GenerateUrl(out node, null, actionName, controllerName, protocol, hostName, null, routeValues, urlHelper.RouteCollection, urlHelper.RequestContext, true));
 }
 private static string GenerateUrlEx(UrlHelper urlHelper, string routeName, string actionName, string controllerName, RouteValueDictionary routeValues)
 {
     IDynamicNode node; return(UrlHelperEx.GenerateUrl(out node, routeName, actionName, controllerName, routeValues, urlHelper.RouteCollection, urlHelper.RequestContext, true));
 }
 public static string RouteUrlEx(this UrlHelper urlHelper, string routeName, RouteValueDictionary routeValues, string protocol, string hostName)
 {
     IDynamicNode node; return(UrlHelperEx.GenerateUrl(out node, routeName, null, null, protocol, hostName, null, routeValues, urlHelper.RouteCollection, urlHelper.RequestContext, false));
 }