示例#1
0
        //public static IActionResult AddRouteValues(this IActionResult result, 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 NameValueCollection(nameValueCollection);
        //        filtered.Remove(null);
        //        filtered.CopyTo(result.GetRouteValueDictionary(), 0);
        //    }
        //    else
        //    {
        //        nameValueCollection.CopyTo(result.GetRouteValueDictionary(), replaceEntries: true);
        //    }
        //    return result;
        //}

        public static IActionResult AddRouteValue(this IActionResult result, string name, object value)
        {
            RouteValueDictionary routeValues = result.GetRouteValueDictionary();

            ModelUnbinderHelpers.AddRouteValues(routeValues, name, value);
            return(result);
        }
示例#2
0
        public string PrevPageUrl(IUrlHelper url, IActionResult route)
        {
            var idx = route.GetRouteValueDictionary();

            idx["Page"] = Math.Max(1, Page - 1);

            return(url.Action(route));
        }
示例#3
0
        public string NextPageUrl(IUrlHelper url, IActionResult route)
        {
            var idx = route.GetRouteValueDictionary();

            idx["Page"] = Math.Min(TotalPages(), Page + 1);

            return(url.Action(route));
        }
示例#4
0
        public static IActionResult AddRouteValues(this IActionResult 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);
        }
示例#5
0
        public string OrderbyUrl(IUrlHelper url, LambdaExpression expression, IActionResult route)
        {
            var propertyName = ExpressionHelper.GetExpressionText(expression);
            var idx          = route.GetRouteValueDictionary();

            if (OrderBy == propertyName)
            {
                idx["OrderByDescending"] = !OrderByDescending;
            }
            else
            {
                idx["OrderBy"]           = propertyName;
                idx["OrderByDescending"] = false;
            }

            return(url.Action(route));
        }
示例#6
0
        public static IHtmlContent AutoNamedRouteLink(this IHtmlHelper htmlHelper, string linkText, IActionResult result, IDictionary <string, object> htmlAttributes, string protocol = null, string hostName = null, string fragment = null)
        {
            string routeName = autoRouteNameFromActionResult(result);

            return(htmlHelper.RouteLink(linkText, routeName, protocol ?? result.GetR4MvcResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), htmlAttributes));
        }
示例#7
0
 public static MvcForm BeginRouteForm(this IHtmlHelper htmlHelper, string routeName, IActionResult result, FormMethod formMethod = FormMethod.Post, IDictionary <string, object> htmlAttributes = null)
 {
     return(htmlHelper.BeginRouteForm(routeName, result.GetRouteValueDictionary(), formMethod, null, htmlAttributes));
 }
示例#8
0
 public static IHtmlContent ActionLink(this IHtmlHelper htmlHelper, string linkText, IActionResult result, object htmlAttributes = null, string protocol = null, string hostName = null, string fragment = null)
 {
     return(htmlHelper.RouteLink(linkText, null, protocol ?? result.GetR4MvcResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
 }
示例#9
0
 public static string Action(this IUrlHelper urlHelper, IActionResult result, string protocol = null, string hostName = null, string fragment = null)
 {
     return(urlHelper.RouteUrl(null, result.GetRouteValueDictionary(), protocol ?? result.GetR4MvcResult().Protocol, hostName, fragment));
 }
示例#10
0
        public static string ActionAbsolute(this IUrlHelper urlHelper, IActionResult result)
        {
            var request = urlHelper.ActionContext.HttpContext.Request;

            return($"{request.Scheme}://{request.Host}{urlHelper.RouteUrl(result.GetRouteValueDictionary())}");
        }