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


C# UI.ViewUserControl类代码示例

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


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

示例1: SetViewItem

        public void SetViewItem() {
            // Arrange
            ViewUserControl vuc = new ViewUserControl();
            object viewItem = new object();
            vuc.ViewData = new ViewDataDictionary(viewItem);

            // Act
            vuc.ViewData.Model = viewItem;
            object newViewItem = vuc.ViewData.Model;

            // Assert
            Assert.AreSame(viewItem, newViewItem);
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:13,代码来源:ViewUserControlTest.cs

示例2: ModelProperty

        public void ModelProperty() {
            // Arrange
            object model = new object();
            ViewDataDictionary viewData = new ViewDataDictionary(model);
            ViewUserControl viewUserControl = new ViewUserControl();
            viewUserControl.ViewData = viewData;

            // Act
            object viewPageModel = viewUserControl.Model;

            // Assert
            Assert.AreEqual(model, viewPageModel);
            Assert.AreEqual(model, viewUserControl.ViewData.Model);
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:14,代码来源:ViewUserControlTest.cs

示例3: SetViewItemOnBaseClassPropagatesToDerivedClass

        public void SetViewItemOnBaseClassPropagatesToDerivedClass() {
            // Arrange
            ViewUserControl<object> vucInt = new ViewUserControl<object>();
            ViewUserControl vuc = vucInt;
            vuc.ViewData = new ViewDataDictionary();
            object o = new object();

            // Act
            vuc.ViewData.Model = o;

            // Assert
            Assert.AreEqual(o, vucInt.ViewData.Model);
            Assert.AreEqual(o, vuc.ViewData.Model);
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:14,代码来源:ViewUserControlTest.cs

示例4: ModelPropertyStronglyTyped

        public void ModelPropertyStronglyTyped() {
            // Arrange
            FooModel model = new FooModel();
            ViewDataDictionary<FooModel> viewData = new ViewDataDictionary<FooModel>(model);
            ViewUserControl<FooModel> viewUserControl = new ViewUserControl<FooModel>();
            viewUserControl.ViewData = viewData;

            // Act
            object viewPageModelObject = ((ViewUserControl)viewUserControl).Model;
            FooModel viewPageModelPerson = viewUserControl.Model;

            // Assert
            Assert.AreEqual(model, viewPageModelObject);
            Assert.AreEqual(model, viewPageModelPerson);
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:15,代码来源:ViewUserControlTest.cs

示例5: GetUrlHelperFromRegularPage

        public void GetUrlHelperFromRegularPage()
        {
            // Arrange
            ViewUserControl vuc = new ViewUserControl();
            Page containerPage = new Page();
            containerPage.Controls.Add(vuc);

            // Assert
            Assert.Throws<InvalidOperationException>(
                delegate { UrlHelper foo = vuc.Url; },
                "A ViewUserControl can be used only in pages that derive from ViewPage or ViewPage<TModel>.");
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:12,代码来源:ViewUserControlTest.cs

示例6: GetUrlHelperFromViewPage

        public void GetUrlHelperFromViewPage()
        {
            // Arrange
            ViewUserControl vuc = new ViewUserControl();
            ViewPage containerPage = new ViewPage();
            containerPage.Controls.Add(vuc);
            RequestContext rc = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());
            UrlHelper urlHelper = new UrlHelper(rc);
            containerPage.Url = urlHelper;

            // Assert
            Assert.Equal(vuc.Url, urlHelper);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:13,代码来源:ViewUserControlTest.cs

示例7: GetHtmlHelperFromViewPage

        public void GetHtmlHelperFromViewPage()
        {
            // Arrange
            ViewUserControl vuc = new ViewUserControl();
            ViewPage containerPage = new ViewPage();
            containerPage.Controls.Add(vuc);
            ViewContext vc = new Mock<ViewContext>().Object;
            vuc.ViewContext = vc;

            // Act
            HtmlHelper htmlHelper = vuc.Html;

            // Assert
            Assert.Equal(vc, htmlHelper.ViewContext);
            Assert.Equal(vuc, htmlHelper.ViewDataContainer);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:16,代码来源:ViewUserControlTest.cs

示例8: GetViewDataFromViewUserControlWithViewDataKeyOnOuterControl

        public void GetViewDataFromViewUserControlWithViewDataKeyOnOuterControl()
        {
            // Arrange
            ViewPage p = new ViewPage();
            p.Controls.Add(new Control());
            ViewUserControl outerVuc = new ViewUserControl() { ViewDataKey = "SubData" };
            p.Controls[0].Controls.Add(outerVuc);
            outerVuc.Controls.Add(new Control());
            ViewUserControl vuc = new ViewUserControl();
            outerVuc.Controls[0].Controls.Add(vuc);

            p.ViewData = new ViewDataDictionary { { "FirstName", "Joe" }, { "LastName", "Schmoe" } };
            p.ViewData["SubData"] = new ViewDataDictionary { { "FirstName", "SubJoe" }, { "LastName", "SubSchmoe" } };

            // Act
            object firstName = vuc.ViewData.Eval("FirstName");
            object lastName = vuc.ViewData.Eval("LastName");

            // Assert
            Assert.Equal("SubJoe", firstName);
            Assert.Equal("SubSchmoe", lastName);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:22,代码来源:ViewUserControlTest.cs

示例9: GetViewDataFromViewPageWithViewDataKeyPointingToViewDataDictionary

        public void GetViewDataFromViewPageWithViewDataKeyPointingToViewDataDictionary()
        {
            // Arrange
            ViewDataDictionary vdd = new ViewDataDictionary()
            {
                { "Foo", "FooParent" },
                { "Bar", "BarParent" },
                {
                    "Child",
                    new ViewDataDictionary()
                    {
                        { "Foo", "FooChild" },
                        { "Bar", "BarChild" }
                    }
                    }
            };

            ViewPage p = new ViewPage();
            p.Controls.Add(new Control());
            ViewUserControl vuc = new ViewUserControl() { ViewDataKey = "Child" };
            p.Controls[0].Controls.Add(vuc);
            p.ViewData = vdd;

            // Act
            object oFoo = vuc.ViewData.Eval("Foo");
            object oBar = vuc.ViewData.Eval("Bar");

            // Assert
            Assert.Equal(vdd["Child"], vuc.ViewData);
            Assert.Equal("FooChild", oFoo);
            Assert.Equal("BarChild", oBar);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:32,代码来源:ViewUserControlTest.cs

示例10: ViewBagProperty_PropagatesChangesToViewData

        public void ViewBagProperty_PropagatesChangesToViewData()
        {
            // Arrange
            ViewPage containerPage = new ViewPage();
            ViewUserControl userControl = new ViewUserControl();
            containerPage.Controls.Add(userControl);
            userControl.ViewData["A"] = 1;

            // Act
            userControl.ViewBag.A = "foo";
            userControl.ViewBag.B = 2;

            // Assert
            Assert.Equal("foo", userControl.ViewData["A"]);
            Assert.Equal(2, userControl.ViewData["B"]);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:16,代码来源:ViewUserControlTest.cs

示例11: GetHtmlHelperFromRegularPage

        public void GetHtmlHelperFromRegularPage() {
            // Arrange
            ViewUserControl vuc = new ViewUserControl();
            Page containerPage = new Page();
            containerPage.Controls.Add(vuc);

            // Assert
            ExceptionHelper.ExpectException<InvalidOperationException>(
                 delegate {
                     HtmlHelper foo = vuc.Html;
                 },
                 "A ViewUserControl can be used only in pages that derive from ViewPage or ViewPage<TViewItem>.");
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:13,代码来源:ViewUserControlTest.cs

示例12: GetViewDataFromViewPage

        public void GetViewDataFromViewPage() {
            // Arrange
            ViewPage p = new ViewPage();
            p.Controls.Add(new Control());
            ViewUserControl vuc = new ViewUserControl();
            p.Controls[0].Controls.Add(vuc);
            p.ViewData = new ViewDataDictionary { { "FirstName", "Joe" }, { "LastName", "Schmoe" } };

            // Act
            object firstName = vuc.ViewData.Eval("FirstName");
            object lastName = vuc.ViewData.Eval("LastName");

            // Assert
            Assert.AreEqual("Joe", firstName);
            Assert.AreEqual("Schmoe", lastName);
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:16,代码来源:ViewUserControlTest.cs

示例13: GetViewDataWhenNoPageSetThrows

        public void GetViewDataWhenNoPageSetThrows() {
            ViewUserControl vuc = new ViewUserControl();
            vuc.AppRelativeVirtualPath = "~/Foo.ascx";

            ExceptionHelper.ExpectException<InvalidOperationException>(
                delegate {
                    var foo = vuc.ViewData["Foo"];
                },
                "The ViewUserControl '~/Foo.ascx' cannot find an IViewDataContainer object. The ViewUserControl must be inside a ViewPage, a ViewMasterPage, or another ViewUserControl.");
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:10,代码来源:ViewUserControlTest.cs

示例14: ViewBagProperty_ReflectsViewData

        public void ViewBagProperty_ReflectsViewData()
        {
            // Arrange
            ViewPage containerPage = new ViewPage();
            ViewUserControl userControl = new ViewUserControl();
            containerPage.Controls.Add(userControl);
            userControl.ViewData["A"] = 1;

            // Act & Assert
            Assert.NotNull(userControl.ViewBag);
            Assert.Equal(1, userControl.ViewBag.A);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:12,代码来源:ViewUserControlTest.cs

示例15: SetViewItemToWrongTypeThrows

        public void SetViewItemToWrongTypeThrows()
        {
            // Arrange
            ViewUserControl<string> vucString = new ViewUserControl<string>();
            vucString.ViewData = new ViewDataDictionary<string>();
            ViewUserControl vuc = vucString;

            // Act & Assert
            Assert.Throws<InvalidOperationException>(
                delegate { vuc.ViewData.Model = 50; },
                "The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'System.String'.");
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:12,代码来源:ViewUserControlTest.cs


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