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


C# ViewDataDictionary类代码示例

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


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

示例1: ColorPicker

 public ColorPicker(ViewContext viewContext, IJavaScriptInitializer initializer, ViewDataDictionary viewData)
     : base(viewContext, initializer, viewData)
 {
     Palette = ColorPickerPalette.None;
     Enabled = true;
     Buttons = true;
 }
开发者ID:wanaxe,项目名称:Study,代码行数:7,代码来源:ColorPicker.cs

示例2: RenderPartialWithViewNameAndViewData

        public void RenderPartialWithViewNameAndViewData() {
            // Arrange
            SpyHtmlHelper helper = SpyHtmlHelper.Create();
            ViewDataDictionary viewData = new ViewDataDictionary();
            Mock<IViewEngine> engine = new Mock<IViewEngine>(MockBehavior.Strict);
            Mock<IView> view = new Mock<IView>(MockBehavior.Strict);

            helper.SpiedEngine = engine.Object;
            helper.ViewData["Foo"] = "Foo";
            viewData["Bar"] = "Bar";

            engine
                .Expect(e => e.FindPartialView(It.IsAny<ControllerContext>(), _partialViewName, It.IsAny<bool>()))
                .Returns(new ViewEngineResult(view.Object, engine.Object))
                .Verifiable();
            view
                .Expect(v => v.Render(It.IsAny<ViewContext>(), helper.ViewContext.HttpContext.Response.Output))
                .Callback<ViewContext, TextWriter>(
                    (viewContext, writer) => {
                        Assert.AreSame(helper.ViewContext.View, viewContext.View);
                        Assert.AreNotSame(helper.ViewData, viewContext.ViewData);
                        Assert.AreSame(helper.ViewContext.TempData, viewContext.TempData);
                        Assert.AreEqual("Bar", viewContext.ViewData["Bar"]);
                        Assert.IsFalse(viewContext.ViewData.ContainsKey("Foo"));
                    })
                .Verifiable();

            // Act
            helper.RenderPartial(_partialViewName, viewData);

            // Assert
            engine.Verify();
            view.Verify();
        }
开发者ID:sanyaade-mobiledev,项目名称:ASP.NET-Mvc-2,代码行数:34,代码来源:RenderPartialExtensionsTest.cs

示例3: ColorPalette

        public ColorPalette(ViewContext viewContext, IJavaScriptInitializer initializer, ViewDataDictionary viewData)
            : base(viewContext, initializer, viewData)
        {
            Palette = ColorPickerPalette.Basic;

            Columns = ColumnsDefault;
        }
开发者ID:jstevenson81,项目名称:wodgeaux,代码行数:7,代码来源:ColorPalette.cs

示例4: Process

 public IList<ResourceListViewModel> Process(IList<Resource> resources, ViewDataDictionary viewdata, string tagName)
 {
     var resourceListViewModel = ResourceMapper.MapFromDomainListToListViewModel(resources);
     StoreTicksOfCreateTimeInViewData(resourceListViewModel, viewdata);
     viewdata["tagName"] = tagName;
     return resourceListViewModel;
 }
开发者ID:JohnCai,项目名称:agilewizard,代码行数:7,代码来源:ResourceListViewProcessor.cs

示例5: RenderPartial

        private static void RenderPartial(HtmlHelper htmlHelper, string partialViewName, ViewDataDictionary viewData, object model, TextWriter writer)
        {
            ViewDataDictionary newViewData;
            if (model == null)
            {
                newViewData = viewData == null ? new ViewDataDictionary(htmlHelper.ViewData) : new ViewDataDictionary(viewData);
            }
            else
            {
                newViewData = viewData == null ? new ViewDataDictionary(model) : new ViewDataDictionary(viewData) { Model = model };
            }

            var controller = htmlHelper.ViewContext.Controller as Controller;
            var viewEngineCollection = controller != null ? controller.ViewEngineCollection : ViewEngines.Engines;
            var newViewContext = new ViewContext(htmlHelper.ViewContext, htmlHelper.ViewContext.View, newViewData, htmlHelper.ViewContext.TempData, writer);
            var result = viewEngineCollection.FindPartialView(newViewContext, partialViewName);
            if (result.View != null)
            {
                result.View.Render(newViewContext, writer);
            }
            else
            {
                var locationsText = new StringBuilder();
                foreach (string location in result.SearchedLocations)
                {
                    locationsText.AppendLine();
                    locationsText.Append(location);
                }

                throw new InvalidOperationException("The partial view '{0}' was not found or no view engine supports the searched locations. The following locations were searched: {1}".Arrange(partialViewName, locationsText));
            }
        }
开发者ID:RifasRazick,项目名称:feather,代码行数:32,代码来源:HtmlHelperExtensions.cs

示例6: GetViewDataWithSelectList

 private static ViewDataDictionary GetViewDataWithSelectList() {
     ViewDataDictionary viewData = new ViewDataDictionary();
     SelectList selectList = new SelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", "C");
     viewData["foo"] = selectList;
     viewData["foo.bar"] = selectList;
     return viewData;
 }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:7,代码来源:SelectExtensionsTest.cs

示例7: SetViewDataForDate

        public static void SetViewDataForDate(ViewDataDictionary ViewData)
        {
            List<string> genderList = new List<string>();
            genderList.Add("Male");
            genderList.Add("Female");
            SelectList list = new SelectList(genderList);
            ViewData["gender"] = list;

            int[] dayA = new int[31];

            for (int i = 0; i < 31; i++)
            {
                dayA[i] = i + 1;
            }

            int[] yearA = new int[100];

            for (int i = 0; i < 100; i++)
            {
                yearA[i] = DateTime.Now.Year - i;
            }

            SelectList daySL = new SelectList(dayA);
            ViewData["days"] = daySL;

            SelectList yearSL = new SelectList(yearA);
            ViewData["years"] = yearSL;
        }
开发者ID:Ripudamangithub,项目名称:saringan-suarez-dayrit,代码行数:28,代码来源:ProfileController.cs

示例8: Execute_ResolvesView_WithDefaultAsViewName

        public void Execute_ResolvesView_WithDefaultAsViewName()
        {
            // Arrange
            var view = new Mock<IView>(MockBehavior.Strict);
            view.Setup(v => v.RenderAsync(It.IsAny<ViewContext>()))
                .Returns(Task.FromResult(result: true))
                .Verifiable();

            var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
            viewEngine.Setup(e => e.FindPartialView(It.IsAny<ActionContext>(), It.IsAny<string>()))
                      .Returns(ViewEngineResult.Found("Default", view.Object))
                      .Verifiable();

            var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());

            var result = new ViewViewComponentResult
            {
                ViewEngine = viewEngine.Object,
                ViewData = viewData
            };

            var viewComponentContext = GetViewComponentContext(view.Object, viewData);

            // Act
            result.Execute(viewComponentContext);

            // Assert
            viewEngine.Verify();
            view.Verify();
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:30,代码来源:ViewViewComponentResultTest.cs

示例9: RenderPartial

 public static void RenderPartial(this AjaxHelper ajaxHelper,
                                  string partialViewName,
                                  object model = null,
                                  ViewDataDictionary viewData = null)
 {
     throw new NotImplementedException();
 }
开发者ID:ruze00,项目名称:Kickbox,代码行数:7,代码来源:RenderPartial.cs

示例10: Sortable

 public Sortable(ViewContext viewContext, IJavaScriptInitializer javaScriptInitializer, ViewDataDictionary viewData)
     : base(viewContext, javaScriptInitializer, viewData)
 {
     CursorOffset = new SortableCursorOffset();
     HintHandler = new ClientHandlerDescriptor();
     PlaceholderHandler = new ClientHandlerDescriptor();
 }
开发者ID:akhuang,项目名称:Zing,代码行数:7,代码来源:Sortable.cs

示例11: OnException

        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            // If custom errors are disabled, we need to let the normal ASP.NET exception handler
            // execute so that the user can see useful debugging information.
            if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled)
            {
                return;
            }

            Exception exception = filterContext.Exception;

            // If this is not an HTTP 500 (for example, if somebody throws an HTTP 404 from an action method),
            // ignore it.
            if (new HttpException(null, exception).GetHttpCode() != 500)
            {
                return;
            }

            if (!ExceptionType.IsInstanceOfType(exception))
            {
                return;
            }

            string controllerName = (string)filterContext.RouteData.Values["controller"];
            string actionName = (string)filterContext.RouteData.Values["action"];
            HandleErrorInfo model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);

            if (this._logger.IsErrorEnabled)
            {
                this._logger.Error(string.Format("An unexpected error occured while executing {0} in {1}.", actionName, controllerName), exception);
            }

            MessageViewData messageViewData = new MessageViewData();

            while (exception != null)
            {
                messageViewData.AddErrorMessage(this._localizer.GetString(exception.Message));
                exception = exception.InnerException;
            }
            var viewData = new ViewDataDictionary<HandleErrorInfo>(model);
            viewData["Messages"] = messageViewData;

            // Render error view
            filterContext.Result = new ViewResult
                                   	{
                                   		ViewName = View,
                                   		MasterName = Master,
                                   		ViewData = viewData,
                                   		TempData = filterContext.Controller.TempData
                                   	};

            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
            filterContext.HttpContext.Response.StatusCode = 500;
        }
开发者ID:xwyangjshb,项目名称:cuyahoga,代码行数:60,代码来源:ExceptionFilter.cs

示例12: 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

示例13: BaseViewHelper

 public BaseViewHelper(RequestContext requestContext, ViewContext viewContext, IViewDataContainer viewDataContainer, RouteCollection routeCollection)
 {
     ViewData = new ViewDataDictionary(viewDataContainer.ViewData);
     RequestContext = requestContext;
     ViewContext = viewContext;
     RouteCollection = routeCollection;
 }
开发者ID:pleb,项目名称:Chillow,代码行数:7,代码来源:BaseViewHelper.cs

示例14: SetBrandSearchViewData

 public void SetBrandSearchViewData(ProductSearchQuery query, ViewDataDictionary viewData)
 {
     ProductOptionSearchData productOptionSearchData = _productOptionManager.GetSearchData(query);
     viewData["product-options"] = productOptionSearchData.AttributeOptions;
     viewData["product-specifications"] = productOptionSearchData.SpecificationOptions;
     viewData["max-price"] = _productSearchIndexService.GetMaxPrice(query);
 }
开发者ID:neozhu,项目名称:Ecommerce,代码行数:7,代码来源:ProductSearchQueryService.cs

示例15: PropertiesInitializedCorrectly

        public void PropertiesInitializedCorrectly()
        {
            // Arrange
            var viewData = new ViewDataDictionary<string>(new EmptyModelMetadataProvider());

            // Act & Assert
            Assert.Empty(viewData);
            Assert.Equal(0, viewData.Count);
            Assert.False(viewData.IsReadOnly);

            Assert.NotNull(viewData.Keys);
            Assert.Empty(viewData.Keys);

            Assert.Null(viewData.Model);
            Assert.NotNull(viewData.ModelMetadata);
            Assert.NotNull(viewData.ModelState);

            Assert.NotNull(viewData.TemplateInfo);
            Assert.Equal(0, viewData.TemplateInfo.TemplateDepth);
            Assert.Equal(string.Empty, viewData.TemplateInfo.FormattedModelValue);
            Assert.Equal(string.Empty, viewData.TemplateInfo.HtmlFieldPrefix);

            Assert.NotNull(viewData.Values);
            Assert.Empty(viewData.Values);
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:25,代码来源:ViewDataOfTTest.cs


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