public IHtmlContent ActionLink(UrlHelper Url, dynamic Shape, object Value) { var RouteValues = (object)Shape.RouteValues; RouteValueDictionary rvd; if (RouteValues == null) { rvd = new RouteValueDictionary(); } else { rvd = RouteValues as RouteValueDictionary ?? new RouteValueDictionary(RouteValues); } var action = Url.Action((string)rvd["action"], (string)rvd["controller"], rvd); IEnumerable<string> classes = Shape.Classes; IDictionary<string, string> attributes = Shape.Attributes; attributes["href"] = action; string id = Shape.Id; var tag = Orchard.DisplayManagement.Shapes.Shape.GetTagBuilder("a", id, classes, attributes); tag.InnerHtml.AppendHtml(CoerceHtmlString(Value)); return tag; }
private void Redirect(HttpContext context, String action, String controller, Object values) { RouteData route = (context.Features[typeof(IRoutingFeature)] as IRoutingFeature).RouteData; IUrlHelper url = new UrlHelper(new ActionContext(context, route, new ActionDescriptor())); context.Response.Redirect(url.Action(action, controller, values)); }
private TagBuilder getRefreshButtonTagBuilder(string captchaDivId, string captchaToken) { IUrlHelper urlHelper = new Microsoft.AspNetCore.Mvc.Routing.UrlHelper(ViewContext); var actionUrl = urlHelper.Action(action: nameof(DNTCaptchaImageController.Refresh), controller: nameof(DNTCaptchaImageController).Replace("Controller", string.Empty), values: new { rndDate = DateTime.Now.Ticks, area = "", BackColor = BackColor, FontName = FontName, FontSize = FontSize, ForeColor = ForeColor, Language = Language, Max = Max, Min = Min, Placeholder = Placeholder, TextBoxClass = TextBoxClass, TextBoxTemplate = TextBoxTemplate, ValidationErrorMessage = ValidationErrorMessage, ValidationMessageClass = ValidationMessageClass, CaptchaToken = captchaToken, RefreshButtonClass = RefreshButtonClass }); var refreshButton = new TagBuilder("a"); var dntCaptchaRefreshButton = "dntCaptchaRefreshButton"; refreshButton.Attributes.Add("id", dntCaptchaRefreshButton); refreshButton.Attributes.Add("name", dntCaptchaRefreshButton); refreshButton.Attributes.Add("href", "#refresh"); refreshButton.Attributes.Add("data-ajax-url", actionUrl); refreshButton.Attributes.Add("data-ajax", "true"); refreshButton.Attributes.Add("data-ajax-method", "POST"); refreshButton.Attributes.Add("data-ajax-mode", "replace-with"); refreshButton.Attributes.Add("data-ajax-update", $"#{captchaDivId}"); refreshButton.Attributes.Add("data-ajax-begin", DataAjaxBeginFunctionName); refreshButton.Attributes.Add("class", RefreshButtonClass); return(refreshButton); }
private static ClientModelValidationContext GetValidationContextWithArea(string currentArea) { var serviceCollection = GetServiceCollection(localizerFactory: null); var serviceProvider = serviceCollection.BuildServiceProvider(); var routeCollection = GetRouteCollectionWithArea(serviceProvider); var routeData = new RouteData { Routers = { routeCollection, }, Values = { { "action", "Index" }, { "controller", "Home" }, }, }; if (!string.IsNullOrEmpty(currentArea)) { routeData.Values["area"] = currentArea; } var actionContext = GetActionContext(serviceProvider, routeData); var urlHelper = new UrlHelper(actionContext); var factory = new Mock<IUrlHelperFactory>(MockBehavior.Strict); factory .Setup(f => f.GetUrlHelper(actionContext)) .Returns(urlHelper); // Make an IUrlHelperFactory available through the ActionContext. serviceCollection.AddSingleton<IUrlHelperFactory>(factory.Object); serviceProvider = serviceCollection.BuildServiceProvider(); actionContext.HttpContext.RequestServices = serviceProvider; return new ClientModelValidationContext( actionContext, _metadata, _metadataProvider, new AttributeDictionary()); }
private string GetAbsoluteUrl(string controllerName, string actionName) { ActionContext actionContext = Url.ActionContext; IUrlHelper urlHelper = new UrlHelper(actionContext); string url = urlHelper.Action(actionName, controllerName); string absoluteUrl = string.Empty; if (url != null) { HttpRequest request = actionContext.HttpContext.Request; absoluteUrl = request.Scheme + "://" + request.Host + url; } return absoluteUrl; }