Ejemplo n.º 1
0
        private static string GenerateLinkInternal(RequestContext requestContext, RouteCollection routeCollection, string linkText, string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary <string, object> htmlAttributes, bool includeImplicitMvcValues)
        {
            string     url        = UrlHelper.GenerateUrl(routeName, actionName, controllerName, protocol, hostName, fragment, routeValues, routeCollection, requestContext, includeImplicitMvcValues);
            TagBuilder tagBuilder = new TagBuilder("a")
            {
                InnerHtml = (!String.IsNullOrEmpty(linkText)) ? HttpUtility.HtmlEncode(linkText) : String.Empty
            };

            tagBuilder.MergeAttributes(htmlAttributes);
            tagBuilder.MergeAttribute("href", url);
            return(tagBuilder.ToString(TagRenderMode.Normal));
        }
        public static MvcAnchor BeginActionLink(this AjaxHelper helper, string actionName, string controllerName, RouteValueDictionary routeValues, AjaxOptions ajaxOptions, RouteValueDictionary htmlAttributes)
        {
            var targetUrl = UrlHelper.GenerateUrl(null, actionName, controllerName, routeValues, helper.RouteCollection, helper.ViewContext.RequestContext, true);
            var builder   = new TagBuilder("a");

            builder.MergeAttributes(htmlAttributes);
            builder.MergeAttribute("href", targetUrl);
            builder.MergeAttributes(ajaxOptions.ToUnobtrusiveHtmlAttributes());
            helper.ViewContext.Writer.Write(builder.ToString(TagRenderMode.StartTag));

            return(new MvcAnchor(helper.ViewContext));
        }
Ejemplo n.º 3
0
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            string destinationUrl = UrlHelper.GenerateUrl(RouteName, null /* actionName */, null /* controllerName */, RouteValues, Routes, context.RequestContext, false /* includeImplicitMvcValues */);

            if (String.IsNullOrEmpty(destinationUrl))
            {
                throw new InvalidOperationException(MvcResources.ActionRedirectResult_NoRouteMatched);
            }

            context.HttpContext.Response.Redirect(destinationUrl, false /* endResponse */);
        }
Ejemplo n.º 4
0
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (context.IsChildAction)
            {
                throw new InvalidOperationException(
                          MvcResources.RedirectAction_CannotRedirectInChildAction
                          );
            }

            string destinationUrl = UrlHelper.GenerateUrl(
                RouteName,
                null /* actionName */
                ,
                null /* controllerName */
                ,
                RouteValues,
                Routes,
                context.RequestContext,
                false /* includeImplicitMvcValues */
                );

            if (String.IsNullOrEmpty(destinationUrl))
            {
                throw new InvalidOperationException(MvcResources.Common_NoRouteMatched);
            }

            context.Controller.TempData.Keep();

            if (Permanent)
            {
                context.HttpContext.Response.RedirectPermanent(destinationUrl, endResponse: false);
            }
            else
            {
                context.HttpContext.Response.Redirect(destinationUrl, endResponse: false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 生成分页链接Url
        /// </summary>
        /// <param name="htmlHelper">HtmlHelper</param>
        /// <param name="page">页码</param>
        /// <param name="options">配置</param>
        /// <returns></returns>
        internal static string GeneratePaginationUrl(this HtmlHelper htmlHelper, long page, BootstrapPagedButtonOptions options)
        {
            if (!htmlHelper.ViewContext.IsChildAction && htmlHelper.ViewContext.RouteData.Values.TryGetValue("page", out object pageIndexObj))
            {
                htmlHelper.ViewContext.RouteData.Values["page"] = page;

                return(UrlHelper.GenerateUrl(options.RouteName, options.ActionName, options.ControllerName, htmlHelper.ViewContext.RouteData.Values, RouteTable.Routes, htmlHelper.ViewContext.RequestContext, false));
            }

            var currentUrl = htmlHelper.ViewContext.RequestContext.HttpContext.Server.HtmlEncode(htmlHelper.ViewContext.HttpContext.Request.RawUrl);

            if (currentUrl.IndexOf("?") == -1)
            {
                return(string.Format("{0}?page={1}", currentUrl, page));
            }

            if (currentUrl.IndexOf("page=", StringComparison.InvariantCultureIgnoreCase) == -1)
            {
                return(string.Format("{0}&page={1}", currentUrl, page));
            }
            return(Regex.Replace(currentUrl, @"page=(\d+\.?\d*|\.\d+)", $"page={page}", RegexOptions.IgnoreCase | RegexOptions.Compiled));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 输出AjaxForm表单
        /// </summary>
        /// <param name="htmlHelper">被扩展的htmlHelper实例</param>
        /// <param name="routeName"></param>
        /// <param name="routeValues"></param>
        /// <param name="method">表单请求方式</param>
        /// <param name="options">异步提交表单选项</param>
        /// <param name="htmlAttributes">表单html属性集合</param>
        /// <returns>MvcForm</returns>
        public static MvcForm BeginAjaxRouteForm(this HtmlHelper htmlHelper, string routeName, RouteValueDictionary routeValues, FormMethod method, AjaxFormOptions options, IDictionary <string, object> htmlAttributes)
        {
            string formAction = UrlHelper.GenerateUrl(routeName, null /* actionName */, null /* controllerName */, routeValues ?? new RouteValueDictionary(), htmlHelper.RouteCollection, htmlHelper.ViewContext.RequestContext, false /* includeImplicitMvcValues */);

            return(FormHelper(htmlHelper, formAction, method, options, htmlAttributes));
        }