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); }
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)); }
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; }
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); }
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result) { return htmlHelper.RouteLink(linkText, result.GetRouteValueDictionary()); }
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, IDictionary<string, object> htmlAttributes) { return htmlHelper.RouteLink(linkText, result.GetRouteValueDictionary(), htmlAttributes); }
public static MvcHtmlString SecureActionLink(this AjaxHelper ajaxHelper, string linkText, ActionResult result, AjaxOptions ajaxOptions) { return ajaxHelper.RouteLink(linkText, result.GetRouteValueDictionary(), ajaxOptions); }
/// <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; }
public static MvcHtmlString SecureActionLink(this AjaxHelper ajaxHelper, string linkText, ActionResult result, AjaxOptions ajaxOptions) { return(ajaxHelper.RouteLink(linkText, result.GetRouteValueDictionary(), ajaxOptions)); }
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)); }
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)); }
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)); }
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))); }
public static TransferToRouteResult TransferToAction(this Controller controller, ActionResult result) { return new TransferToRouteResult(result.GetRouteValueDictionary()); }
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))); }
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result) { return(htmlHelper.RouteLink(linkText, result.GetRouteValueDictionary())); }
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)); }
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)); }
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)); }
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); }
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); }
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); }
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)); }
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); }
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; }
public static string Action(this UrlHelper urlHelper, ActionResult result) { return urlHelper.RouteUrl(null, result.GetRouteValueDictionary()); }
public static string Action(this UrlHelper urlHelper, ActionResult result) { return(urlHelper.RouteUrl(null, result.GetRouteValueDictionary())); }
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)); }
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))); }
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())); }
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()))); }
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); }
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)); }
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); }
public static string ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, IDictionary <string, object> htmlAttributes) { return(htmlHelper.RouteLink(linkText, result.GetRouteValueDictionary(), htmlAttributes)); }