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

C# Mvc.ViewContext类代码示例

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

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



ViewContext类属于System.Web.Mvc命名空间,在下文中一共展示了ViewContext类的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: Render

 public void Render(ViewContext viewContext, TextWriter writer)
 {
     using (MiniProfiler.Current.Step("Render " + (isPartial ? "partial" : "") + ": " + name))
     {
         wrapped.Render(viewContext, writer);
     }
 }
开发者ID:jfheins,项目名称:WARR-Protokoll,代码行数:7,代码来源:ProfilingViewEngine.cs


示例3: Add

 public JsonResult Add(string name, string visitDate, string arrivalDate, string contact, string emailAddress, int visitType, int officeID, int eventID, int convensionID, int serviceID, int fsmID, int bookingStatus, float gsbAmount, float donationAmount)
 {
     var audienceManager = new DataAccess.AudienceManager();
     var visitDateTime = Convert.ToDateTime(visitDate);
     DateTime? arrivalDateTime = string.IsNullOrEmpty(arrivalDate) ? (DateTime?)null : Convert.ToDateTime(arrivalDate);
     var audienceID = audienceManager.Add(name, contact, emailAddress, visitDateTime, arrivalDateTime, visitType, officeID, eventID, fsmID, convensionID, serviceID, bookingStatus, gsbAmount, donationAmount);
     if (audienceID != 0)
     {
         using (var sw = new StringWriter())
         {
             var fsmSelectionMail = audienceManager.GetFSMSelectionSlipByAudienceID(audienceID);
             ViewData.Model = fsmSelectionMail;
             ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, "FSMSelectionMail");
             ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
             try
             {
                 viewResult.View.Render(viewContext, sw);
                 audienceManager.SendSelectionSlipMail(fsmID, emailAddress, sw.GetStringBuilder().ToString());
             }
             catch (Exception ex)
             { }
         }
     }
     return Json(audienceID);
 }
开发者ID:dharabagadiya,项目名称:SimplePlatform,代码行数:25,代码来源:AudiencesController.cs


示例4: VeneerScripts_handles_content_types_with_no_scripts

        public void VeneerScripts_handles_content_types_with_no_scripts()
        {
            // Arrange
            var service = new Mock<IContentService>();
            var content = new Content
            {
                RefreshDate = DateTime.Now,
                Sections = new List<ContentSection>
                {
                    new ContentSection
                    {
                        Id = "Footer", Html = "<div id='hello' />", Scripts = new List<ContentScript>()
                    }
                }
            };
            service.Setup(x => x.Get(It.IsAny<ContentTypes>())).Returns(content);
            var contentTypes = new List<ContentTypes> { ContentTypes.Footer };

            var model = new VeneerBaseViewModel(service.Object, contentTypes);

            var viewContext = new ViewContext();
            var viewDataContainer = new Mock<IViewDataContainer>();
            var htmlHelper = new HtmlHelper(viewContext, viewDataContainer.Object);

            // Act
            var result = htmlHelper.VeneerScripts(model).ToHtmlString();

            // Assert
            Assert.That(result, Is.Empty);
        }
开发者ID:ukp-webdev,项目名称:veneer-client,代码行数:30,代码来源:VeneerHtmlHelperExtensionsTests.cs


示例5: ScriptRegistrar

        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptRegistrar"/> class.
        /// </summary>
        /// <param name="scripts">The scripts.</param>
        /// <param name="scriptableComponents">The scriptable components.</param>
        /// <param name="viewContext">The view context.</param>
        /// <param name="assetItemMerger">The asset merger.</param>
        /// <param name="scriptWrapper">The script wrapper.</param>
        public ScriptRegistrar(WebAssetCollection scripts, IList<IScriptableComponent> scriptableComponents, ViewContext viewContext, IWebAssetCollectionResolver resolver, ScriptWrapperBase scriptWrapper)
        {
            this.resolver = resolver;

            if (viewContext.HttpContext.Items[Key] != null)
            {
                throw new InvalidOperationException(Resources.TextResource.OnlyOneScriptRegistrarIsAllowedInASingleRequest);
            }

            viewContext.HttpContext.Items[Key] = this;

            OutputScriptFiles = true;

            DefaultGroup = new WebAssetGroup("default", false) { DefaultPath = WebAssetDefaultSettings.ScriptFilesPath };
            Scripts = scripts;
            Scripts.Insert(0, DefaultGroup);

            this.scriptableComponents = scriptableComponents;
            ViewContext = viewContext;
            ScriptWrapper = scriptWrapper;
            AssetHandlerPath = WebAssetHttpHandler.DefaultPath;

            OnDocumentReadyActions = new List<Action>();
            OnDocumentReadyStatements = new List<string>();
            OnWindowUnloadActions = new List<Action>();
            OnWindowUnloadStatements = new List<string>();
        }
开发者ID:vialpando09,项目名称:RallyPortal2,代码行数:35,代码来源:ScriptRegistrar.cs


示例6: Render

        public void Render(ViewContext viewContext, TextWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            // Reading the file content
            var text = File.ReadAllText(_filepath);

            // Page doctype
            var doctype = "<!doctype html>";

            // Page encoding
            var charset = "<meta charset=\"utf-8\" />";

            // Page title
            var title = "<title>" + Path.GetFileNameWithoutExtension(_filepath) + "</title>";

            // Page CSS (if any)
            var css = string.IsNullOrWhiteSpace(_cssHref) ?
                string.Format(CultureInfo.InvariantCulture, "<style>\n{0}\n</style>", Resources.Style) :
                string.Format(CultureInfo.InvariantCulture, "<link rel=\"stylesheet\" href=\"{0}\">", _cssHref);

            // Parsing the Markdown content
            var markdown = CommonMarkConverter.Convert(text);

            // Joining all up
            var content = string.Join("\n", doctype, charset, title, css, markdown);

            // Writing to the stream
            writer.Write(content);
        }
开发者ID:tallesl,项目名称:net-MarkdownMvc,代码行数:31,代码来源:MarkdownView.cs


示例7: RenderHtmlOutput

        private void RenderHtmlOutput(ControllerContext context)
        {
            IView viewEngineResult = ViewEngines.Engines.FindView(context, this.ViewName, null).View;

            var viewContext = new ViewContext(context, viewEngineResult, context.Controller.ViewData, context.Controller.TempData, context.HttpContext.Response.Output);
            viewEngineResult.Render(viewContext, context.HttpContext.Response.Output);
        }
开发者ID:flextry,项目名称:MvcRazorToWord,代码行数:7,代码来源:WordActionResult.cs


示例8: CreateEditor

        public static Editor CreateEditor()
        {
            Mock<HttpContextBase> httpContext = TestHelper.CreateMockedHttpContext();

            httpContext.Setup(c => c.Request.Browser.CreateHtmlTextWriter(It.IsAny<TextWriter>())).Returns(new HtmlTextWriter(TextWriter.Null));

            Mock<IViewDataContainer> viewDataContainer = new Mock<IViewDataContainer>();

            viewDataContainer.SetupGet(container => container.ViewData).Returns(new ViewDataDictionary());

            Mock<IClientSideObjectWriterFactory> clientSideObjectWriterFactory = new Mock<IClientSideObjectWriterFactory>();
            clientSideObjectWriter = new Mock<IClientSideObjectWriter>();

            viewContext = TestHelper.CreateViewContext();
            viewContext.ViewData = new ViewDataDictionary();

            clientSideObjectWriterFactory.Setup(c => c.Create(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TextWriter>())).Returns(clientSideObjectWriter.Object);

            viewContext = TestHelper.CreateViewContext();
            viewContext.ViewData = new ViewDataDictionary();

            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(url => url.Generate(It.IsAny<RequestContext>(), It.IsAny<INavigatable>())).Returns(string.Empty);
            return new Editor(viewContext, clientSideObjectWriterFactory.Object, new Mock<IWebAssetCollectionResolver>().Object, CreateLocalizationService(), urlGenerator.Object)
            {
                Name = "Editor"
            };
        }
开发者ID:vialpando09,项目名称:RallyPortal2,代码行数:28,代码来源:EditorTestHelper.cs


示例9: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (string.IsNullOrEmpty(ViewName))
                this.ViewName = context.RouteData.GetRequiredString("action");

            ViewEngineResult result = null;

            if (View == null)
                View = FindView(context).View;

            using (StringWriter output = new StringWriter())
            {
                ViewData["_isGriddlySettingsRequest"] = true;

                ViewContext viewContext = new ViewContext(context, View, ViewData, TempData, output);

                View.Render(viewContext, output);

                Settings = ViewData["settings"] as GriddlySettings;
            }

            if (result != null)
                result.ViewEngine.ReleaseView(context, View);
        }
开发者ID:programcsharp,项目名称:griddly,代码行数:27,代码来源:GriddlySettingsResult.cs


示例10: Create

 /// <summary>
 /// Create a new HtmlHelper with a fake context and container
 /// </summary>
 /// <returns>HtmlHelper</returns>
 public static HtmlHelper Create()
 {
     var vc = new ViewContext();
     vc.HttpContext = new FakeHttpContext();
     var html = new HtmlHelper(vc, new FakeViewDataContainer());
     return html;
 }
开发者ID:gabrielgreen,项目名称:FluentHtmlHelpers,代码行数:11,代码来源:HtmlHelperFactory.cs


示例11: RenderPartial

        public static string RenderPartial(this ControllerBase self, string viewName, object model,
            bool strip = true)
        {
            var context = self.ControllerContext;

            if (string.IsNullOrEmpty(viewName)) {
                viewName = context.RouteData.GetRequiredString("action");
            }

            self.ViewData.Model = model;

            //try {
            using (var writer = new StringWriter()) {
                var viewResult = ViewEngines.Engines.FindPartialView(context, viewName);
                var viewContext = new ViewContext(context, viewResult.View, self.ViewData,
                    self.TempData, writer);
                viewResult.View.Render(viewContext, writer);

                var result = writer.GetStringBuilder().ToString();
                return strip ? _stripper.Replace(result, StripInvalidChars) : result;
            }
            //} catch (ArgumentNullException ex) { }

            //return "";
        }
开发者ID:brendanhay,项目名称:Shared,代码行数:25,代码来源:ControllerExtensions.cs


示例12: ConfigureContext

 private Action<IModelValueContainer> ConfigureContext(ViewContext viewContext)
 {
     return c => {
     ConfigureModel(viewContext, c.TalModel);
     ConfigureModel(viewContext, c.MetalModel);
       };
 }
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:7,代码来源:ZptView.cs


示例13: Render

 public void Render(ViewContext viewContext, TextWriter writer)
 {
     var doc = CreateDocument();
       doc.Render(writer,
          contextConfigurator: ConfigureContext(viewContext),
          options: RenderingOptions);
 }
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:7,代码来源:ZptView.cs


示例14: Render

        public void Render(ViewContext viewContext, TextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (page == null)
            {
                throw new InvalidOperationException("Cannot create a page from " + viewPath);
            }
            //damn, now why is this internal, how can you ever reuse the webviewpage then??
            //page.OverridenLayoutPath = this.LayoutPath;
            if (!String.IsNullOrEmpty(this.LayoutPath))
                page.Layout = LayoutPath;

            page.VirtualPath = viewPath;
            page.ViewContext = viewContext;
            page.ViewData = viewContext.ViewData;
            page.InitHelpers();
            WebPageRenderingBase startPage = null;
            if (this.RunViewStartPages)
            {
                startPage = this.StartPageLookup(page, VirtualPathFactoryManagerViewEngine.ViewStartFileName, this.ViewStartFileExtensions);
            }
            var httpContext = viewContext.HttpContext;
            WebPageRenderingBase base4 = null;
            object model = null;

            //instead of page.OverridenLayoutPath:
            if (!String.IsNullOrEmpty(this.LayoutPath))
                page.Layout = LayoutPath;

            page.ExecutePageHierarchy(new WebPageContext(httpContext, base4, model), writer, startPage);
        }
开发者ID:Alxandr,项目名称:AppVisum.Sys,代码行数:34,代码来源:CompiledWebViewPageView.cs


示例15: RenderSitecorePlaceHolder

        public static string RenderSitecorePlaceHolder(string key)
        {
            var sublayoutId = GetSublayoutIdFromPlaceHolder(Sitecore.Context.Item[Sitecore.FieldIDs.LayoutField], key);
            if (!string.IsNullOrEmpty(sublayoutId))
            {
                var layoutItem = Sitecore.Context.Database.GetItem(ID.Parse(sublayoutId));
                var controllerName = layoutItem.Fields["Controller"].Value;
                var actionName = layoutItem.Fields["Action"].Value;

                HttpContext.Current.RewritePath(string.Concat("/", controllerName, "/", actionName));

                RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));
                if (routeData != null)
                {
                    var factory = new ControllerFactory();
                    var httpContextBase = new HttpContextWrapper(HttpContext.Current);
                    var context = new RequestContext(httpContextBase, routeData);
                    Type type = factory.GetController(context, controllerName);

                    if (type != null)
                    {
                        var controller = (Controller)factory.GetController(context, type);

                        var controllerContext = new ControllerContext(httpContextBase, routeData, controller);
                        var viewContext = new ViewContext(controllerContext, new FakeView(), controller.ViewData, controller.TempData, TextWriter.Null);

                        var helper = new HtmlHelper(viewContext, new ViewPage());

                        return helper.Action(actionName, controllerName).ToHtmlString();
                    }
                }
                HttpContext.Current.RewritePath("default.aspx");
            }
            return "";
        }
开发者ID:bplasmeijer,项目名称:SitecoreMVC,代码行数:35,代码来源:RazorControl.cs


示例16: BuildControl

 protected virtual void BuildControl(TagBuilder builder, CustomFieldDefinition fieldDefinition, string fieldValue, object htmlAttributes, ViewContext viewContext)
 {
     if (htmlAttributes != null)
     {
         builder.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), true);
     }
 }
开发者ID:Kooboo,项目名称:Ecommerce,代码行数:7,代码来源:FormControlBase.cs


示例17: Render

        public virtual void Render(ViewContext viewContext, TextWriter writer)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException("viewContext");
            }

            object instance = null;

            Type type = BuildManager.GetCompiledType(ViewPath);
            if (type != null)
            {
                instance = ViewPageActivator.Create(_controllerContext, type);
            }

            if (instance == null)
            {
                throw new InvalidOperationException(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        MvcResources.CshtmlView_ViewCouldNotBeCreated,
                        ViewPath));
            }

            RenderView(viewContext, writer, instance);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:26,代码来源:BuildManagerCompiledView.cs


示例18: Render

        public GridItemAction Render(object dataItem, GridItemAction itemAction, ViewContext viewContext)
        {
            var inheritable = dataItem as IInheritable;
            if (inheritable != null)
            {
                var localized = inheritable.IsLocalized(Site.Current);
                if (localized)
                {
                    //注释下面的代码,解决子页面本地化,父页面没有本地化时,不能进行还原操作。
                    var hasParent = Site.Current.Parent != null;
                    if (hasParent)
                    {
                        itemAction.ActionName = "Unlocalize";
                        itemAction.Title = "Unlocalize".Localize();
                        itemAction.Class = "o-icon unlocalize actionCommand";
                        itemAction.ConfirmMessage = "Are you sure you want to unlocalize this item?";
                        itemAction.Visible = true;
                    }
                    else
                    {
                        itemAction.Title = "Localize";
                        itemAction.Visible = false;
                    }
                }

            }

            return itemAction;
        }
开发者ID:Godoy,项目名称:CMS,代码行数:29,代码来源:InheritableGridActionVisibleArbiter.cs


示例19: ActivateAndRenderTemplate

        private string ActivateAndRenderTemplate(IRazorTemplateBase obj, DisplayContext displayContext, string templateVirtualPath, object model)
        {
            var buffer = new StringBuilder(1024);
            using (var writer = new StringWriter(buffer)) {
                using (var htmlWriter = new HtmlTextWriter(writer)) {

                    if (displayContext != null && displayContext.ViewContext.Controller != null) {
                        var shapeViewContext = new ViewContext(
                            displayContext.ViewContext.Controller.ControllerContext,
                            displayContext.ViewContext.View,
                            displayContext.ViewContext.ViewData,
                            displayContext.ViewContext.TempData,
                            htmlWriter
                            );

                        obj.WebPageContext = new WebPageContext(displayContext.ViewContext.HttpContext, obj as WebPageRenderingBase, model);
                        obj.ViewContext = shapeViewContext;

                        obj.ViewData = new ViewDataDictionary(displayContext.ViewDataContainer.ViewData) {Model = model};
                        obj.InitHelpers();
                    }
                    else {

                        obj.ViewData = new ViewDataDictionary(model);
                        obj.WebPageContext = new WebPageContext(_httpContextBase, obj as WebPageRenderingBase, model);
                    }

                    obj.VirtualPath = templateVirtualPath ?? "~/Themes/Orchard.Templates";
                    obj.Render(htmlWriter);
                }
            }

            return buffer.ToString();
        }
开发者ID:Zlatinsz,项目名称:podnebeto,代码行数:34,代码来源:RazorTemplateProcessor.cs


示例20: DatePicker

 public DatePicker(ViewContext viewContext, IJavaScriptInitializer initializer, ViewDataDictionary viewData)
     : base(viewContext, initializer, viewData)
 {
     Min = defaultMinDate;
     Max = defaultMaxDate;
     MonthTemplate = new MonthTemplate();
 }
开发者ID:danielkaradachki,项目名称:HomeWork,代码行数:7,代码来源:DatePicker.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Mvc.ViewResult类代码示例发布时间:2022-05-26
下一篇:
C# Mvc.ValueProviderResult类代码示例发布时间: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