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

C# ViewDataDictionary类代码示例

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

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



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


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


示例17: RenderViewToString

        public static string RenderViewToString(string controllerName, string viewName, object viewData, List<KeyValuePair<string, object>> additionalData)
        {
            var context = HttpContext.Current;
              var contextBase = new HttpContextWrapper(context);
              var routeData = new RouteData();
              routeData.Values.Add("controller", controllerName);

              var controllerContext = new ControllerContext(contextBase,
            routeData,
            new EmptyController());

              var razorViewEngine = new RazorViewEngine();
              var razorViewResult = razorViewEngine.FindView(controllerContext,
            viewName,
            "",
            false);

              ViewDataDictionary vdd = new ViewDataDictionary(viewData);
              if (additionalData != null && additionalData.Any())
            additionalData.ForEach(vdd.Add);

              var writer = new StringWriter();
              var viewContext = new ViewContext(controllerContext,
            razorViewResult.View,
            vdd,
            new TempDataDictionary(),
            writer);
              razorViewResult.View.Render(viewContext, writer);

              return writer.ToString();
        }
开发者ID:shanmukhig,项目名称:tms,代码行数:31,代码来源:RenderView.cs


示例18: Merge

 public static ViewDataDictionary Merge(this ViewDataDictionary source, ViewDataDictionary dic1)
 {
     if (dic1 != null)
     {
         foreach (KeyValuePair<string, object> pair in dic1)
         {
             if (!source.ContainsKey(pair.Key))
             {
                 source.Add(pair.Key, pair.Value);
             }
         }
         foreach (KeyValuePair<string, ModelState> pair2 in dic1.ModelState)
         {
             if (!source.ModelState.ContainsKey(pair2.Key))
             {
                 source.ModelState.Add(pair2.Key, pair2.Value);
             }
         }
         if (source.Model == null)
         {
             source.Model = dic1.Model;
         }
         if (source.TemplateInfo == null)
         {
             source.TemplateInfo = dic1.TemplateInfo;
         }
         if (source.ModelMetadata == null)
         {
             source.ModelMetadata = dic1.ModelMetadata;
         }
     }
     return source;
 }
开发者ID:Epitomy,项目名称:CMS,代码行数:33,代码来源:ViewDataDictionaryExtensions.cs


示例19: Index

		//
		// GET: /Test/

		public ActionResult Index()
		{
			StringWriter sw = new StringWriter();
			IFileSystem files = N2.Context.Current.Resolve<IFileSystem>();
			List<ContentRegistration> expressions = new List<ContentRegistration>();
			foreach (var file in files.GetFiles("~/Dinamico/Themes/Default/Views/ContentPages/").Where(f => f.Name.EndsWith(".cshtml")))
			{
				var cctx = new ControllerContext(ControllerContext.HttpContext, new RouteData(), new ContentPagesController());
				cctx.RouteData.Values.Add("controller", "DynamicPages");
				var v = ViewEngines.Engines.FindView(cctx, file.VirtualPath, null);

				if (v.View == null)
					sw.Write(string.Join(", ", v.SearchedLocations.ToArray()));
				else
				{
					var temp = new ContentPage();
					cctx.RequestContext.RouteData.ApplyCurrentPath(new N2.Web.PathData(temp));
					var vdd = new ViewDataDictionary { Model = temp };
					var re = new ContentRegistration(new DefinitionMap().GetOrCreateDefinition(typeof(ContentPage)).Clone());
					N2.Web.Mvc.Html.RegistrationExtensions.SetRegistrationExpression(cctx.HttpContext, re);
					v.View.Render(new ViewContext(cctx, v.View, vdd, new TempDataDictionary(), sw), sw);
					expressions.Add(re);
				}
			}
			return View(expressions);
		}
开发者ID:meixger,项目名称:n2cms,代码行数:29,代码来源:TestController.cs


示例20: EvalReturnsSimplePropertyValue

        public void EvalReturnsSimplePropertyValue()
        {
            var obj = new { Foo = "Bar" };
            ViewDataDictionary vdd = new ViewDataDictionary(obj);

            Assert.Equal("Bar", vdd.Eval("Foo"));
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:7,代码来源:ViewDataDictionaryTest.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# ViewEngineCollection类代码示例发布时间:2022-05-24
下一篇:
C# ViewContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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