• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Rendering.ViewContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.AspNet.Mvc.Rendering.ViewContext的典型用法代码示例。如果您正苦于以下问题:C# ViewContext类的具体用法?C# ViewContext怎么用?C# ViewContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ViewContext类属于Microsoft.AspNet.Mvc.Rendering命名空间,在下文中一共展示了ViewContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetValidationAttributes

 protected override IDictionary<string, object> GetValidationAttributes(
     ViewContext viewContext,
     ModelExplorer modelExplorer,
     string name)
 {
     return ValidationAttributes;
 }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:7,代码来源:TestableHtmlGenerator.cs


示例2: CopyConstructor_CopiesExpectedProperties

        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 HtmlContentWrapperTextWriter(new HtmlContentBuilder(), Encoding.UTF8);

            // 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);
        }
开发者ID:phinq19,项目名称:git_example,代码行数:35,代码来源:ViewContextTests.cs


示例3: SettingViewData_AlsoUpdatesViewBag

        public void SettingViewData_AlsoUpdatesViewBag()
        {
            // Arrange
            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(new HttpContextAccessor(), 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"]);
        }
开发者ID:4myBenefits,项目名称:Mvc,代码行数:25,代码来源:ViewContextTests.cs


示例4: CartSummaryComponent_Returns_CartedItems

        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);
        }
开发者ID:rosslyn-cuongle,项目名称:MusicStore,代码行数:34,代码来源:CartSummaryComponentTest.cs


示例5: SettingViewData_AlsoUpdatesViewBag

        public void SettingViewData_AlsoUpdatesViewBag()
        {
            // Arrange (eventually passing null to these consturctors will throw)
            var context = new ViewContext(
                new ActionContext(null, null, null),
                view: null,
                viewData: null,
                tempData: null,
                writer: null,
                htmlHelperOptions: new HtmlHelperOptions());
            var originalViewData = context.ViewData = new ViewDataDictionary(metadataProvider: new EmptyModelMetadataProvider());
            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"]);
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:25,代码来源:ViewContextTests.cs


示例6: WidgetContext

        /// <summary>
        /// Initialises a new instance of <see cref="WidgetContext"/>.
        /// </summary>
        /// <param name="widgetDescriptor">The widget descriptor.</param>
        /// <param name="values">The set of provided invocation values.</param>
        /// <param name="viewContext">The view context.</param>
        /// <param name="writer">The text writer.</param>
        public WidgetContext(WidgetDescriptor widgetDescriptor, RouteValueDictionary values, ViewContext viewContext, TextWriter writer)
        {
            if (widgetDescriptor == null)
            {
                throw new ArgumentNullException(nameof(widgetDescriptor));
            }

            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            if (viewContext == null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            WidgetDescriptor = widgetDescriptor;
            Values = values;

            ViewContext = new ViewContext(
                viewContext,
                viewContext.View,
                new ViewDataDictionary(viewContext.ViewData),
                writer);
        }
开发者ID:Antaris,项目名称:AspNetCore.Mvc.Widgets,代码行数:38,代码来源:WidgetContext.cs


示例7: CreateHelper

 public dynamic CreateHelper(ViewContext viewContext)
 {
     return new DisplayHelper(
         _displayManager,
         _shapeFactory,
         viewContext);
 }
开发者ID:freemsly,项目名称:Orchard2,代码行数:7,代码来源:DisplayHelperFactory.cs


示例8: TemplateRenderer

        public TemplateRenderer(
            IViewEngine viewEngine,
            ViewContext viewContext,
            ViewDataDictionary viewData,
            string templateName,
            bool readOnly)
        {
            if (viewEngine == null)
            {
                throw new ArgumentNullException(nameof(viewEngine));
            }

            if (viewContext == null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }

            if (viewData == null)
            {
                throw new ArgumentNullException(nameof(viewData));
            }

            _viewEngine = viewEngine;
            _viewContext = viewContext;
            _viewData = viewData;
            _templateName = templateName;
            _readOnly = readOnly;
        }
开发者ID:4myBenefits,项目名称:Mvc,代码行数:28,代码来源:TemplateRenderer.cs


示例9: ViewLocalizer_UseIndexerWithArguments_ReturnsLocalizedString

        public void ViewLocalizer_UseIndexerWithArguments_ReturnsLocalizedString()
        {
            // Arrange
            var applicationEnvironment = new Mock<IApplicationEnvironment>();
            applicationEnvironment.Setup(a => a.ApplicationName).Returns("TestApplication");

            var localizedString = new LocalizedString("Hello", "Bonjour test");

            var htmlLocalizer = new Mock<IHtmlLocalizer>();
            htmlLocalizer.Setup(h => h["Hello", "test"]).Returns(localizedString);

            var htmlLocalizerFactory = new Mock<IHtmlLocalizerFactory>();
            htmlLocalizerFactory.Setup(
                h => h.Create("TestApplication.example", "TestApplication")).Returns(htmlLocalizer.Object);

            var viewLocalizer = new ViewLocalizer(htmlLocalizerFactory.Object, applicationEnvironment.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", "test"];

            // Assert
            Assert.Equal(localizedString, actualLocalizedString);
        }
开发者ID:notami18,项目名称:Mvc,代码行数:30,代码来源:ViewLocalizerTest.cs


示例10: RenderPageAsync

        private async Task<RazorTextWriter> RenderPageAsync(IRazorPage page,
                                                            ViewContext context,
                                                            bool executeViewStart)
        {
            using (var bufferedWriter = new RazorTextWriter(context.Writer.Encoding))
            {
                // The writer for the body is passed through the ViewContext, allowing things like HtmlHelpers
                // and ViewComponents to reference it.
                var oldWriter = context.Writer;
                context.Writer = bufferedWriter;
                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;
                }
            }
        }
开发者ID:Nakro,项目名称:Mvc,代码行数:27,代码来源:RazorView.cs


示例11: MvcForm

        public MvcForm([NotNull] ViewContext viewContext)
        {
            _viewContext = viewContext;

            // Push the new FormContext; GenerateEndForm() does the corresponding pop.
            _viewContext.FormContext = new FormContext();
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:7,代码来源:MvcForm.cs


示例12: Create

 private static TempDataResponseProvider Create(ViewContext context, string key)
 {
     if (context.TempData == null) return Empty();
     if (!context.TempData.ContainsKey(key)) return Empty();
     var bucket = context.TempData[key] as IEnumerable<IServerResponse>;
     if (bucket == null || !bucket.Any()) return Empty();
     return new TempDataResponseProvider(bucket);
 }
开发者ID:mitsbits,项目名称:Ubik.MVC5,代码行数:8,代码来源:TempDataResponseProvider.cs


示例13: GetValue

        private string GetValue(ViewContext viewContext, ModelExpression modelExpression)
        {
            string value = base.GetValue(viewContext, modelExpression);

              if (string.IsNullOrEmpty(value))
            return false.ToString().ToLower();

              return value.ToLower();
        }
开发者ID:rajendra1809,项目名称:Platformus,代码行数:9,代码来源:CheckBoxTagHelperBase.cs


示例14: GenerateInput

        private TagBuilder GenerateInput(ViewContext viewContext, ModelExpression modelExpression)
        {
            TagBuilder tb = new TagBuilder("input");

              tb.Attributes.Add("name", this.GetIdentity(modelExpression));
              tb.Attributes.Add("type", "hidden");
              tb.Attributes.Add("value", this.GetValue(viewContext, modelExpression));
              return tb;
        }
开发者ID:rajendra1809,项目名称:Platformus,代码行数:9,代码来源:CheckBoxTagHelperBase.cs


示例15: MvcForm

        /// <summary>
        /// Initializes a new instance of <see cref="MvcForm"/>.
        /// </summary>
        /// <param name="viewContext">The <see cref="ViewContext"/>.</param>
        public MvcForm(ViewContext viewContext)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }

            _viewContext = viewContext;
        }
开发者ID:phinq19,项目名称:git_example,代码行数:13,代码来源:MvcForm.cs


示例16: DisplayHelper

 public DisplayHelper(
     IDisplayManager displayManager,
     IShapeFactory shapeFactory,
     ViewContext viewContext)
 {
     _displayManager = displayManager;
     _shapeFactory = shapeFactory;
     ViewContext = viewContext;
 }
开发者ID:adwardliu,项目名称:Orchard2,代码行数:9,代码来源:DisplayHelper.cs


示例17: RenderAsync

        public Task RenderAsync(ViewContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return Task.FromResult(0);
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:9,代码来源:NullView.cs


示例18: Contextualize

        public void Contextualize(ViewContext viewContext)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }

            _viewContext = viewContext;
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:9,代码来源:DefaultViewComponentHelper.cs


示例19: GetLayoutName

        public string GetLayoutName(ViewContext viewContext)
        {
            ISiteSettings site = siteResolver.Resolve();
            if (site == null) return options.DefaultLayout;

            string layout = options.DefaultLayout.Replace(".cshtml", string.Empty); // "Default_Layout"

            // resolve tenant specific layout file name
            
            if (options.SelectionMode == LayoutSelectionMode.Convention) 
            {
                // with this mode layouts are not shown in a dropdown list in site settings
                // so the layout cannot be changed from the UI
                // use a convention like Site1Layout.cshtml Site2Layout.cshtml
                // based on siteid
                layout = string.Format(CultureInfo.InvariantCulture, 
                    options.ConventionFormat, 
                    site.SiteId.ToInvariantString());
            }
            else
            {
                // LayoutSelectionMode.Browsing -- this is the default
                // in this mode a dropdown list of available layouts is shown
                // and the layout can be chosen from the UI
                // the list is filtered per tenant using file naming conventions
                // where the SiteID is part of the filename format
                // ie you could name files like this:
                // Site1_dark_Layout.cshtml
                // Site1_light_Layout.cshtml
                // Site2_supercool_Layout.cshtml
                // Site2_autumn_Layout.cshtml
                // ...
                
                if (site.Layout.Length > 0)
                {
                    layout = site.Layout.Replace(".cshtml", string.Empty);
                }
                
            }
            
            // in all cases we need to determine of the layout file exists
            // and if not log something and fallback to a known layout file

            var layoutPageResult = viewEngine.FindPage(viewContext, layout);
            if (layoutPageResult.Page == null)
            {
                log.LogError("could not find the layout " + layout);

                return options.DefaultLayout.Replace(".cshtml", string.Empty);
            }
            
            log.LogDebug("using the layout " + layout);
            return layout;
            

                
        }
开发者ID:ludev,项目名称:cloudscribe,代码行数:57,代码来源:TenantLayoutSelector.cs


示例20: Contextualize

 public void Contextualize(ViewContext viewContext)
 {
     var baseName = viewContext.View.Path.Replace('/', '.').Replace('\\', '.');
     if (baseName.StartsWith("."))
     {
         baseName = baseName.Substring(1);
     }
     baseName = _appName + "." + baseName;
     _localizer = _localizerFactory.Create(baseName, _appName);
 }
开发者ID:morarsebastian,项目名称:i18nStarterWeb,代码行数:10,代码来源:ViewLocalizer.cs



注:本文中的Microsoft.AspNet.Mvc.Rendering.ViewContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TagHelpers.CacheTagHelper类代码示例发布时间:2022-05-26
下一篇:
C# Rendering.SelectList类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap