public override async Task ExecuteResultAsync([NotNull] ActionContext context) { var viewEngine = ViewEngine ?? context.HttpContext.RequestServices.GetService<ICompositeViewEngine>(); var viewName = ViewName ?? context.ActionDescriptor.Name; var view = FindView(viewEngine, context, viewName); using (view as IDisposable) { context.HttpContext.Response.ContentType = "text/html; charset=utf-8"; var wrappedStream = new StreamWrapper(context.HttpContext.Response.Body); var encoding = Encodings.UTF8EncodingWithoutBOM; using (var writer = new StreamWriter(wrappedStream, encoding, BufferSize, leaveOpen: true)) { try { var viewContext = new ViewContext(context, view, ViewData, writer); await view.RenderAsync(viewContext); } catch { // Need to prevent writes/flushes on dispose because the StreamWriter will flush even if // nothing got written. This leads to a response going out on the wire prematurely in case an // exception is being thrown inside the try catch block. wrappedStream.BlockWrites = true; throw; } } } }
/// <summary> /// Gets the layout path for view. /// </summary> /// <param name="viewContext"><see cref="ViewContext"/> instance.</param> /// <returns>Returns the layout path for view.</returns> public string GetLayout(ViewContext viewContext) { var themepath = this.GetThemePath(viewContext); var layout = $"{themepath}/Shared/_Layout.cshtml"; return themepath.StartsWith("~/Themes") ? layout.ToLowerInvariant() : layout; }
public IEnumerable<MvcSiteMapNode> GetBreadcrumb(ViewContext context) { String area = context.RouteData.Values["area"] as String; String action = context.RouteData.Values["action"] as String; String controller = context.RouteData.Values["controller"] as String; MvcSiteMapNode current = NodeList.SingleOrDefault(node => String.Equals(node.Area, area, StringComparison.OrdinalIgnoreCase) && String.Equals(node.Action, action, StringComparison.OrdinalIgnoreCase) && String.Equals(node.Controller, controller, StringComparison.OrdinalIgnoreCase)); List<MvcSiteMapNode> breadcrumb = new List<MvcSiteMapNode>(); while (current != null) { breadcrumb.Insert(0, new MvcSiteMapNode { IconClass = current.IconClass, Controller = current.Controller, Action = current.Action, Area = current.Area }); current = current.Parent; } return breadcrumb; }
/// <summary> /// Asynchronously renders the specified <paramref name="view"/> to the response body. /// </summary> /// <param name="view">The <see cref="IView"/> to render.</param> /// <param name="actionContext">The <see cref="ActionContext"/> for the current executing action.</param> /// <param name="viewData">The <see cref="ViewDataDictionary"/> for the view being rendered.</param> /// <param name="tempData">The <see cref="ITempDataDictionary"/> for the view being rendered.</param> /// <returns>A <see cref="Task"/> that represents the asychronous rendering.</returns> public static async Task ExecuteAsync([NotNull] IView view, [NotNull] ActionContext actionContext, [NotNull] ViewDataDictionary viewData, [NotNull] ITempDataDictionary tempData, string contentType) { if (string.IsNullOrEmpty(contentType)) { contentType = ContentType; } actionContext.HttpContext.Response.ContentType = contentType; var wrappedStream = new StreamWrapper(actionContext.HttpContext.Response.Body); var encoding = Encodings.UTF8EncodingWithoutBOM; using (var writer = new StreamWriter(wrappedStream, encoding, BufferSize, leaveOpen: true)) { try { var viewContext = new ViewContext(actionContext, view, viewData, tempData, writer); await view.RenderAsync(viewContext); } catch { // Need to prevent writes/flushes on dispose because the StreamWriter will flush even if // nothing got written. This leads to a response going out on the wire prematurely in case an // exception is being thrown inside the try catch block. wrappedStream.BlockWrites = true; throw; } } }
protected string RenderPartialViewToString(string viewName, object model) { if (string.IsNullOrEmpty(viewName)) { viewName = ControllerContext.ActionDescriptor.ActionName; } ViewData.Model = model; using (StringWriter sw = new StringWriter()) { var engine = _serviceProvider.GetService(typeof(ICompositeViewEngine)) as ICompositeViewEngine; // Resolver.GetService(typeof(ICompositeViewEngine)) as ICompositeViewEngine; ViewEngineResult viewResult = engine.FindView(ControllerContext, viewName, false); ViewContext viewContext = new ViewContext( ControllerContext, viewResult.View, ViewData, TempData, sw, new HtmlHelperOptions() //Added this parameter in ); //Everything is async now! var t = viewResult.View.RenderAsync(viewContext); t.Wait(); return sw.GetStringBuilder().ToString(); } }
private async Task<StringCollectionTextWriter> RenderPageAsync(IRazorPage page, ViewContext context, bool executeViewStart) { var bufferedWriter = new StringCollectionTextWriter(context.Writer.Encoding); var writer = (TextWriter)bufferedWriter; // The writer for the body is passed through the ViewContext, allowing things like HtmlHelpers // and ViewComponents to reference it. var oldWriter = context.Writer; var oldFilePath = context.ExecutingFilePath; context.Writer = writer; context.ExecutingFilePath = page.Path; try { if (executeViewStart) { // Execute view starts using the same context + writer as the page to render. await RenderViewStartAsync(context); } await RenderPageCoreAsync(page, context); return bufferedWriter; } finally { context.Writer = oldWriter; context.ExecutingFilePath = oldFilePath; writer.Dispose(); } }
public ChildActionExtensionsTest() { route = new Mock<RouteBase>(); route.Setup(r => r.GetVirtualPath(It.IsAny<RequestContext>(), It.IsAny<RouteValueDictionary>())) .Returns(() => virtualPathData); virtualPathData = new VirtualPathData(route.Object, "~/VirtualPath"); routes = new RouteCollection(); routes.Add(route.Object); originalRouteData = new RouteData(); string returnValue = ""; httpContext = new Mock<HttpContextBase>(); httpContext.Setup(hc => hc.Request.ApplicationPath).Returns("~"); httpContext.Setup(hc => hc.Response.ApplyAppPathModifier(It.IsAny<string>())) .Callback<string>(s => returnValue = s) .Returns(() => returnValue); httpContext.Setup(hc => hc.Server.Execute(It.IsAny<IHttpHandler>(), It.IsAny<TextWriter>(), It.IsAny<bool>())); viewContext = new ViewContext { RequestContext = new RequestContext(httpContext.Object, originalRouteData) }; viewDataContainer = new Mock<IViewDataContainer>(); htmlHelper = new Mock<HtmlHelper>(viewContext, viewDataContainer.Object, routes); }
private static ViewComponentContext GetViewComponentContext(IView view, Stream stream) { var actionContext = new ActionContext(GetHttpContext(), new RouteData(), new ActionDescriptor()); var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); var viewContext = new ViewContext( actionContext, view, viewData, Mock.Of<ITempDataDictionary>(), TextWriter.Null, new HtmlHelperOptions()); var writer = new StreamWriter(stream) { AutoFlush = true }; var viewComponentDescriptor = new ViewComponentDescriptor() { Type = typeof(object), }; var viewComponentContext = new ViewComponentContext( viewComponentDescriptor, new Dictionary<string, object>(), new HtmlTestEncoder(), viewContext, writer); return viewComponentContext; }
/// <inheritdoc /> public async Task ExecuteAsync(WidgetContext context) { var viewEngine = ViewEngine ?? ResolveViewEngine(context); var viewData = ViewData ?? context.ViewData; bool isNullOrEmptyViewName = string.IsNullOrEmpty(ViewName); string state = null; // TODO: Resolve from value provider? string qualifiedViewName; if (!isNullOrEmptyViewName && (ViewName[0] == '~' || ViewName[0] == '/')) { qualifiedViewName = ViewName; } else { qualifiedViewName = string.Format(ViewPath, context.WidgetDescriptor.ShortName, isNullOrEmptyViewName ? (state ?? DefaultViewName) : ViewName); } var view = FindView(context.ViewContext, viewEngine, qualifiedViewName); var childViewContext = new ViewContext( context.ViewContext, view, viewData, context.Writer); using (view as IDisposable) { await view.RenderAsync(childViewContext); } }
public void Process(ViewContext viewContext, TextWriter writer) { Contract.Assert(viewContext != null); Contract.Assert(writer != null); object view = CreateViewInstance(); if (view == null) { throw new InvalidOperationException(string.Format( CultureInfo.CurrentCulture, "View could not be created : {0}", ViewPath )); } WebViewPage initPage = view as WebViewPage; if (initPage == null) { throw new InvalidOperationException(string.Format( CultureInfo.CurrentCulture, "wrong base type for view: {0}", ViewPath)); } //initPage.OverridenLayoutPath = this.LayoutPath; initPage.VirtualPath = this.ViewPath; // initPage.ViewContext = viewContext; // initPage.ViewData = viewContext.ViewData; initPage.InitHelpers(); initPage.ExecutePageHierarchy(new WebPageContext(), writer, initPage); }
public void PropertiesAreSet() { // Arrange var mockControllerContext = new Mock<ControllerContext>(); mockControllerContext.Setup(o => o.HttpContext.Items).Returns(new Hashtable()); var view = new Mock<IView>().Object; var viewData = new ViewDataDictionary(); var tempData = new TempDataDictionary(); var writer = new StringWriter(); // Act ViewContext viewContext = new ViewContext(mockControllerContext.Object, view, viewData, tempData, writer); // Setting FormContext to null will return the default one later viewContext.FormContext = null; // Assert Assert.Equal(view, viewContext.View); Assert.Equal(viewData, viewContext.ViewData); Assert.Equal(tempData, viewContext.TempData); Assert.Equal(writer, viewContext.Writer); Assert.False(viewContext.UnobtrusiveJavaScriptEnabled); // Unobtrusive JavaScript should be off by default Assert.NotNull(viewContext.FormContext); // We get the default FormContext Assert.Equal("span", viewContext.ValidationSummaryMessageElement); // gen a <span/> by default Assert.Equal("span", viewContext.ValidationMessageElement); // gen a <span/> by default }
private void RenderViewPage(ViewContext context, TextWriter writer, ViewPage page) { page.ViewData = context.ViewData; page.Output = writer; page.RenderView(context); }
private void RenderViewUserControl(ViewContext context, TextWriter writer, ViewUserControl control) { control.ViewData = context.ViewData; control.Output = writer; control.RenderView(context); }
public string PageForContext(ViewContext context) { string name = Preferences.Get<string> (PrefKeyForContext (context)); if (name == null) name = DefaultForContext (context); return name; }
public dynamic CreateHelper(ViewContext viewContext) { return new DisplayHelper( _displayManager, _shapeFactory, viewContext); }
private string DefaultForContext(ViewContext context) { if (context == ViewContext.Edit) return Catalog.GetString ("Edit"); // Don't care otherwise, Tags sounds reasonable return Catalog.GetString ("Tags"); }
public void Process(ViewContext viewContext, TextWriter writer) { object view = CreateViewInstance(); if (view == null) { throw new InvalidOperationException(string.Format( CultureInfo.CurrentCulture, "View could not be created : {0}", ViewPath)); } var initPage = view as IViewPage; if (initPage == null) { throw new InvalidOperationException(string.Format( CultureInfo.CurrentCulture, "wrong base type for view: {0}", ViewPath)); } initPage.Layout = LayoutPath; initPage.VirtualPath = ViewPath; initPage.Context = viewContext.HttpContext; initPage.DataContainer = viewContext.ControllerContext.Data; initPage.SetData(viewContext.ControllerContext.Data.MainModel ?? viewContext.ControllerContext.Data); //initPage.InitHelpers(); var webPageContext = new WebPageContext(viewContext.HttpContext, (WebPageBase) initPage, initPage.GetData()); ((WebPageBase) initPage).ExecutePageHierarchy(webPageContext, writer, (WebPageBase) initPage); }
public Control AddTo(Control container, ViewContext context) { Literal l = new Literal(); l.Text = context.Fragment.Value.Substring(1, context.Fragment.Value.Length - 2); container.Controls.Add(l); return l; }
public Control AddTo(Control container, ViewContext context) { Literal l = new Literal(); l.Text = context.Fragment.Value; container.Controls.Add(l); return l; }
public void ViewLocalizer_UseIndexer_ReturnsLocalizedHtmlString() { // Arrange var hostingEnvironment = new Mock<IHostingEnvironment>(); hostingEnvironment.Setup(a => a.ApplicationName).Returns("TestApplication"); var localizedString = new LocalizedHtmlString("Hello", "Bonjour"); var htmlLocalizer = new Mock<IHtmlLocalizer>(); htmlLocalizer.Setup(h => h["Hello"]).Returns(localizedString); var htmlLocalizerFactory = new Mock<IHtmlLocalizerFactory>(); htmlLocalizerFactory.Setup(h => h.Create("TestApplication.example", "TestApplication")) .Returns(htmlLocalizer.Object); var viewLocalizer = new ViewLocalizer(htmlLocalizerFactory.Object, hostingEnvironment.Object); var view = new Mock<IView>(); view.Setup(v => v.Path).Returns("example"); var viewContext = new ViewContext(); viewContext.View = view.Object; viewLocalizer.Contextualize(viewContext); // Act var actualLocalizedString = viewLocalizer["Hello"]; // Assert Assert.Equal(localizedString, actualLocalizedString); }
public async Task CartSummaryComponent_Returns_CartedItems() { // Arrange var viewContext = new ViewContext() { HttpContext = new DefaultHttpContext() }; // Session initialization var cartId = "CartId_A"; viewContext.HttpContext.Session = new TestSession(); viewContext.HttpContext.Session.SetString("Session", cartId); // DbContext initialization var dbContext = _serviceProvider.GetRequiredService<MusicStoreContext>(); PopulateData(dbContext, cartId, albumTitle: "AlbumA", itemCount: 10); // CartSummaryComponent initialization var cartSummaryComponent = new CartSummaryComponent(dbContext) { ViewComponentContext = new ViewComponentContext() { ViewContext = viewContext } }; // Act var result = await cartSummaryComponent.InvokeAsync(); // Assert Assert.NotNull(result); var viewResult = Assert.IsType<ViewViewComponentResult>(result); Assert.Null(viewResult.ViewName); Assert.Null(viewResult.ViewData.Model); Assert.Equal(10, cartSummaryComponent.ViewBag.CartCount); Assert.Equal("AlbumA", cartSummaryComponent.ViewBag.CartSummary); }
private void RenderView(ScriptScope scope, ViewContext context, TextWriter writer) { scope.SetVariable("view_data", context.ViewData); scope.SetVariable("model", context.ViewData.Model); scope.SetVariable("context", context); scope.SetVariable("response", context.HttpContext.Response); scope.SetVariable("url", new RubyUrlHelper(context.RequestContext)); scope.SetVariable("html", new RubyHtmlHelper(context, new Container(context.ViewData))); scope.SetVariable("ajax", new RubyAjaxHelper(context, new Container(context.ViewData))); var script = new StringBuilder(); Template.ToScript("render_page", script); if (_master != null) _master.Template.ToScript("render_layout", script); else script.AppendLine("def render_layout; yield; end"); script.AppendLine("def view_data.method_missing(methodname); get_Item(methodname.to_s); end"); script.AppendLine("render_layout { |content| render_page }"); try { _rubyEngine.ExecuteScript(script.ToString(), scope); } catch (Exception e) { writer.Write(e.ToString()); } }
public void SettingViewData_AlsoUpdatesViewBag() { // Arrange var httpContext = new DefaultHttpContext(); var originalViewData = new ViewDataDictionary(metadataProvider: new EmptyModelMetadataProvider()); var context = new ViewContext( new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()), view: Mock.Of<IView>(), viewData: originalViewData, tempData: new TempDataDictionary(httpContext, Mock.Of<ITempDataProvider>()), writer: TextWriter.Null, htmlHelperOptions: new HtmlHelperOptions()); var replacementViewData = new ViewDataDictionary(metadataProvider: new EmptyModelMetadataProvider()); // Act context.ViewBag.Hello = "goodbye"; context.ViewData = replacementViewData; context.ViewBag.Another = "property"; // Assert Assert.NotSame(originalViewData, context.ViewData); Assert.Same(replacementViewData, context.ViewData); Assert.Null(context.ViewBag.Hello); Assert.Equal("property", context.ViewBag.Another); Assert.Equal("property", context.ViewData["Another"]); }
/// <summary> /// Renders the specified partial view to a string. /// </summary> /// <param name="viewName">The name of the partial view.</param> /// <param name="model">The model.</param> /// <returns>The partial view as a string.</returns> protected string RenderPartialViewToString(string viewName, object model) { if (string.IsNullOrEmpty(viewName)) { viewName = ControllerContext.RouteData.GetRequiredString("action"); } ViewData.Model = model; using (var sw = new StringWriter()) { // Find the partial view by its name and the current controller context. ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName); if (viewResult.View == null) { throw new ArgumentException(string.Format("Could not find the view with the specified name '{0}'.", viewName), "viewName"); } // Create a view context. var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw); // Render the view using the StringWriter object. viewResult.View.Render(viewContext, sw); return sw.GetStringBuilder().ToString(); } }
public override void RenderView(ViewContext viewContext) { var prevHandler = this.Context.Handler; var isOnAspx = prevHandler is Page; this.Controls.Add(new Placeholder() { Key = key }); if (!isOnAspx) { this.Controls.Add(new SitecoreForm()); } using (var containerPage = new PageHolderContainerPage(this)) { try { if (!isOnAspx) this.Context.Handler = containerPage; if (global::Sitecore.Context.Page == null) { viewContext.Writer.WriteLine("<!-- Unable to use sitecoreplacholder outside sitecore -->"); return; } InitializePageContext(containerPage, viewContext); RenderViewAndRestoreContentType(containerPage, viewContext); } finally { this.Context.Handler = prevHandler; } } }
internal static void InitializePageContext(Page containerPage, ViewContext viewContext) { PageContext pageContext = global::Sitecore.Context.Page; if (pageContext == null) return; var exists = pageContext.Renderings != null && pageContext.Renderings.Count > 0; if (!exists) { //use the default initializer: pageContextInitializer.Invoke(pageContext, null); //viewContext.HttpContext.Items["_SITECORE_PLACEHOLDER_AVAILABLE"] = true; } else { //our own initializer (almost same as Initialize in PageContext, but we need to skip buildcontroltree, since that is already availabe) pageContext_page.SetValue(pageContext, containerPage); containerPage.PreRender += (sender, args) => pageContextOnPreRender.Invoke(pageContext, new[] {sender, args}); switch (Settings.LayoutPageEvent) { case "preInit": containerPage.PreInit += (o, args) => pageContext.Build(); break; case "init": containerPage.Init += (o, args) => pageContext.Build(); break; case "load": containerPage.Load += (o, args) => pageContext.Build(); break; } } }
/// <summary> /// Asynchronously renders the specified <paramref name="view"/> to the response body. /// </summary> /// <param name="view">The <see cref="IView"/> to render.</param> /// <param name="actionContext">The <see cref="ActionContext"/> for the current executing action.</param> /// <param name="viewData">The <see cref="ViewDataDictionary"/> for the view being rendered.</param> /// <param name="tempData">The <see cref="ITempDataDictionary"/> for the view being rendered.</param> /// <returns>A <see cref="Task"/> that represents the asynchronous rendering.</returns> public static async Task ExecuteAsync([NotNull] IView view, [NotNull] ActionContext actionContext, [NotNull] ViewDataDictionary viewData, [NotNull] ITempDataDictionary tempData, [NotNull] HtmlHelperOptions htmlHelperOptions, MediaTypeHeaderValue contentType) { var response = actionContext.HttpContext.Response; contentType = contentType ?? DefaultContentType; if (contentType.Encoding == null) { // Do not modify the user supplied content type, so copy it instead contentType = contentType.Copy(); contentType.Encoding = Encoding.UTF8; } response.ContentType = contentType.ToString(); using (var writer = new HttpResponseStreamWriter(response.Body, contentType.Encoding)) { var viewContext = new ViewContext( actionContext, view, viewData, tempData, writer, htmlHelperOptions); await view.RenderAsync(viewContext); } }
public UnobtrusiveFormContext(ViewContext context, string formId) { _context = context; _context.ClientValidationEnabled = true; _context.UnobtrusiveJavaScriptEnabled = true; _context.FormContext = new FormContext { FormId = formId }; }
public void CopyConstructor_CopiesExpectedProperties() { // Arrange var httpContext = new DefaultHttpContext(); var originalContext = new ViewContext( new ActionContext(httpContext, new RouteData(), new ActionDescriptor()), view: Mock.Of<IView>(), viewData: new ViewDataDictionary(metadataProvider: new EmptyModelMetadataProvider()), tempData: new TempDataDictionary(httpContext, Mock.Of<ITempDataProvider>()), writer: TextWriter.Null, htmlHelperOptions: new HtmlHelperOptions()); var view = Mock.Of<IView>(); var viewData = new ViewDataDictionary(originalContext.ViewData); var writer = new StringWriter(); // Act var context = new ViewContext(originalContext, view, viewData, writer); // Assert Assert.Same(originalContext.ActionDescriptor, context.ActionDescriptor); Assert.Equal(originalContext.ClientValidationEnabled, context.ClientValidationEnabled); Assert.Same(originalContext.ExecutingFilePath, context.ExecutingFilePath); Assert.Same(originalContext.FormContext, context.FormContext); Assert.Equal(originalContext.Html5DateRenderingMode, context.Html5DateRenderingMode); Assert.Same(originalContext.HttpContext, context.HttpContext); Assert.Same(originalContext.ModelState, context.ModelState); Assert.Same(originalContext.RouteData, context.RouteData); Assert.Same(originalContext.TempData, context.TempData); Assert.Same(originalContext.ValidationMessageElement, context.ValidationMessageElement); Assert.Same(originalContext.ValidationSummaryMessageElement, context.ValidationSummaryMessageElement); Assert.Same(view, context.View); Assert.Same(viewData, context.ViewData); Assert.Same(writer, context.Writer); }
public override void Execute(ActionResultContext context, ControllerContext controllerContext, IMonoRailServices services) { ApplyConventions(context); var viewEngines = services.ViewEngines; var result = viewEngines.ResolveView(this.ViewName, this.Layout, new ViewResolutionContext(context)); if (result.Successful) { try { var httpContext = context.HttpContext; var viewContext = new ViewContext(httpContext, httpContext.Response.Output, controllerContext); result.View.Process(viewContext, httpContext.Response.Output); } finally { result.ViewEngine.Release(result.View); } } else { throw new Exception("Could not find view " + this.ViewName + ". Searched at " + string.Join(", ", result.SearchedLocations)); } }
/// <summary> /// Creates a new PixelHelper. /// </summary> /// <param name="viewContext"></param> /// <param name="viewPage"></param> /// <param name="routeCollection"></param> public PixelHelper(ViewContext viewContext, WebViewPage viewPage, RouteCollection routeCollection) { ViewContext = viewContext; ViewData = new ViewDataDictionary(viewPage.ViewData); this.ViewPage = viewPage; }
public static string ChangePasswordNavClass(ViewContext viewContext) => PageNavClass(viewContext, ChangePassword);
public static string IndexNavClass(ViewContext viewContext) => PageNavClass(viewContext, Index);
public static string DeleteNavClass(ViewContext viewContext) => PageNavClass(viewContext, Delete);
public static string DownloadPersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, DownloadPersonalData);
public static string EmailNavClass(ViewContext viewContext) => PageNavClass(viewContext, Email);
public void Render(ViewContext viewContext, TextWriter writer) { throw new NotImplementedException(); }
public static string PageNavClass(ViewContext viewContext, string page) { var activePage = viewContext.ViewData["ActivePage"] as string; return(string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : null); }
public EditorImageBrowserSettingsBuilder(EditorImageBrowserSettings settings, ViewContext viewContext, IUrlGenerator urlGenerator) { this.viewContext = viewContext; this.urlGenerator = urlGenerator; this.settings = settings; }
public static string DetailsNavClass(ViewContext viewContext) => PageNavClass(viewContext, Details);
public static string TwoFactorAuthenticationNavClass(ViewContext viewContext) => PageNavClass(viewContext, TwoFactorAuthentication);
public static string VersionsNavClass(ViewContext viewContext) => PageNavClass(viewContext, Versions);
private static string PageNavClass(ViewContext viewContext, string page) { var activePage = viewContext.ViewData["ActivePage"] as string ?? System.IO.Path.GetFileNameWithoutExtension(viewContext.ActionDescriptor.DisplayName); return string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : null; }
/// <summary> /// Creates a new PixelHelper. /// </summary> /// <param name="viewContext"></param> /// <param name="viewPage"></param> public PixelHelper(ViewContext viewContext, WebViewPage viewPage) : this(viewContext, viewPage, RouteTable.Routes) { }
public static string ManageFreelanceNavClass(ViewContext viewContext) => PageNavClass(viewContext, ManageFreelance);
public InputTypeMvcForm(ViewContext viewContext) : base(viewContext, HtmlEncoder.Default) { _viewContext = viewContext; }
public static string BitCoinNavClass(ViewContext viewContext) => PageNavClass(viewContext, BitCoin);
public static string ManageProjectsNavClass(ViewContext viewContext) => PageNavClass(viewContext, ManageProjects);
public SitecoreMVCSection(ViewContext viewContext, string sectionName) { _writer = viewContext.Writer; this._writer.Write(string.Format("<!--MVCSectionBegin-{0}", sectionName.ToLower())); }
public static string ManageKlientNavClass(ViewContext viewContext) => PageNavClass(viewContext, ManageKlient);
public void Render(ViewContext viewContext, TextWriter writer) { writer.Write("\r\n \r\n This thing has leading and trailing whitespace. \r\n \r\n"); }
public static bool HasCookieConsent(ViewContext context) { return(context.ViewBag.HasCookieConsent ?? false); }
public static IUrlHelper GetUrlHelper(this ViewContext viewContext) { var urlHelperFactory = viewContext.HttpContext.RequestServices.GetRequiredService <IUrlHelperFactory>(); return(urlHelperFactory.GetUrlHelper(viewContext)); }
public async Task RenderAsync(ViewContext context) { await context.Writer.WriteLineAsync("world"); }
public static bool IsCurrentPage(ViewContext viewContext, string page) => CurrentPage(viewContext) == page;
public async Task ProcessAsync_AspLinkAttributesSpecifiedWithButtonElementTypeGeneratesFormActionAttribute( string action, string controller, string area, string fragment, string host, string page, string pageHandler, string protocol, string route, IDictionary <string, string> routeValues) { // Arrange var context = new TagHelperContext( tagName: "govuk-button", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>(), uniqueId: "test"); var output = new TagHelperOutput( "govuk-button", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Button text"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var urlHelperFactory = new Mock <IUrlHelperFactory>(); urlHelperFactory .Setup(mock => mock.GetUrlHelper(It.IsAny <ActionContext>())) .Returns((ActionContext actionContext) => { var urlHelper = new Mock <IUrlHelper>(); urlHelper.SetupGet(mock => mock.ActionContext).Returns(actionContext); urlHelper .Setup(mock => mock.Action( /*actionContext: */ It.IsAny <UrlActionContext>())) .Returns("http://place.com"); urlHelper .Setup(mock => mock.Link( /*routeName: */ It.IsAny <string>(), /*values: */ It.IsAny <object>())) .Returns("http://place.com"); urlHelper .Setup(mock => mock.RouteUrl( /*routeContext: */ It.IsAny <UrlRouteContext>())) .Returns("http://place.com"); return(urlHelper.Object); }); var viewContext = new ViewContext() { RouteData = new Microsoft.AspNetCore.Routing.RouteData() }; var tagHelper = new ButtonTagHelper(new DefaultGovUkHtmlGenerator(), urlHelperFactory.Object) { Element = ButtonTagHelperElementType.Button, Action = action, Area = area, Controller = controller, Fragment = fragment, Host = host, Page = page, PageHandler = pageHandler, Protocol = protocol, Route = route, RouteValues = routeValues, ViewContext = viewContext }; // Act await tagHelper.ProcessAsync(context, output); // Assert Assert.Equal("button", output.TagName); Assert.Equal("http://place.com", output.Attributes["formaction"].Value); }
public static string PersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, PersonalData);
public static string GetCurrentNavClass(ViewContext viewContext, string page) => IsCurrentPage(viewContext, page)? "active" : null;
public static string ExternalLoginsNavClass(ViewContext viewContext) => PageNavClass(viewContext, ExternalLogins);
public static string OffersNavClass(ViewContext viewContext) => PageNavClass(viewContext, Offers);