当前位置: 首页>>代码示例>>C#>>正文


C# Rendering.ViewContext类代码示例

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


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


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