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


C# Mvc.MvcHtmlString类代码示例

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


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

示例1: RenderTextWithGuid

 public static MvcHtmlString RenderTextWithGuid(this HtmlHelper helper, string guid)
 {
     var path = GetPathToResource(helper.ViewContext);
     var items = DtoHelper.ToTextItemModel(path);
     var mvcString = new MvcHtmlString(items.First(x => x.Guid == guid).Text);
     return mvcString;
 }
开发者ID:kreviuz,项目名称:Cms-Bsuir,代码行数:7,代码来源:RenderHelper.cs

示例2: Add

        public Line Add(MvcHtmlString label, MvcHtmlString input, bool show = true)
        {
            string html = "{0}<div class='controls controls-row'>{1}</div>";
            string lbl;
            if (show)
            {
                if (MvcHtmlString.IsNullOrEmpty(label))
                {
                    lbl = "<label class='control-label'>&nbsp;</label>";
                }
                else
                {
                    lbl = label.ToString().Replace("<label ", "<label class='control-label' ");
                }
                html = string.Format(html, lbl, input.ToString());

                //TagBuilder l = new TagBuilder("div");
                //l.AddCssClass("control-group");

                //l.InnerHtml += MvcHtmlString.IsNullOrEmpty(label) ? "<label>&nbsp;</label>" : label.ToString();
                //l.InnerHtml += input.ToString();

                p.InnerHtml += html;
            }

            return this;
        }
开发者ID:odairkreuzberg,项目名称:simetrica,代码行数:27,代码来源:FormHelper.cs

示例3: BootstrapTextbox

        public static MvcHtmlString BootstrapTextbox(this HtmlHelper htmlHelper, MvcHtmlString htmlTextBox, string prepend, string append)
        {
            TagBuilder builder = new TagBuilder("div");

            if (!string.IsNullOrEmpty(prepend))
            {
                builder.AddCssClass("input-prepend");
                TagBuilder span = new TagBuilder("span");
                span.AddCssClass("add-on");
                span.InnerHtml += prepend;
                builder.InnerHtml += span;
            }

            builder.InnerHtml += htmlTextBox;

            if (!string.IsNullOrEmpty(append))
            {
                builder.AddCssClass("input-append");
                TagBuilder span = new TagBuilder("span");
                span.AddCssClass("add-on");
                span.InnerHtml += append;
                builder.InnerHtml += span;
            }

            return MvcHtmlString.Create(builder.ToString());
        }
开发者ID:jgennari,项目名称:Mvc.Bootstrap,代码行数:26,代码来源:Fields.cs

示例4: InsertFileContentCached

        public static MvcHtmlString InsertFileContentCached(this HtmlHelper helper, [PathReference] string path, int duration = 0)
        {
            var result = new MvcHtmlString(string.Empty);

            try
            {
                if (Convert.ToBoolean(ConfigurationManager.AppSettings["IgnoreCacheForInsertFileContentCached"]))
                {
                    return InsertFileContent(helper, path);
                }
                var cacheKey = "insertFile|" + path.GetHashCode();
                var cached = HttpRuntime.Cache.Get(cacheKey) as MvcHtmlString;
                if (cached != null)
                {
                    return cached;
                }
                result = InsertFileContent(helper, path);
                HttpRuntime.Cache.Add(cacheKey,
                    result,
                    null /*dependencies*/,
                    Cache.NoAbsoluteExpiration,
                    duration == 0 ? Cache.NoSlidingExpiration : TimeSpan.FromSeconds(duration),
                    CacheItemPriority.Normal,
                    null /*onRemoveCallback*/);
            }
            catch (Exception ex)
            {
                result = new MvcHtmlString("Exception occured at " + path + " details: " + ex.Message);
            }

            return result;
        }
开发者ID:stantoxt,项目名称:BForms,代码行数:32,代码来源:FileUtilities.cs

示例5: InputActionLink

 public static IHtmlString InputActionLink(this AjaxHelper ajaxHelper, ActionResult result, AjaxOptions ajaxOptions)
 {
     var builder = new TagBuilder("input");
     var link = ajaxHelper.ActionLink("[replaceme]", result, ajaxOptions);
     var mvcLink = new MvcHtmlString(link.ToHtmlString().Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing)));
     return mvcLink;
 }
开发者ID:kenwarner,项目名称:scrilla,代码行数:7,代码来源:HtmlHelpers.cs

示例6: AuctionItemDetailModel

        public AuctionItemDetailModel(AuctionItem auctionItem)
        {
            Id = auctionItem.Id;
                        AuctionNumber = auctionItem.AuctionNumber;
                        Title = auctionItem.Title;
                        Description = new MvcHtmlString(auctionItem.Description.Replace(Environment.NewLine, "<br/>"));
                        MinimumPrice = auctionItem.MinimumPrice;
                        Ended = auctionItem.Ended;

                        ImageFileAttachments = new List<int>();
                        foreach (var fileAttachmentAuctionItem in FileAttachmentAuctionItemRepository.Instance.ListByAuctionItem(auctionItem.Id))
                        {
                                ImageFileAttachments.Add(fileAttachmentAuctionItem.FileAttachmentId);
                        }

                        Biddings = new List<AuctionItemBiddingModel>();

                        AuctionItemBiddingRepository.Instance.ListByAuctionItem(auctionItem.Id).ForEach(b => Biddings.Add(new AuctionItemBiddingModel(b)));

                        ImageFileAttachment = 0;
                        if (ImageFileAttachments.Count > 0)
                        {
                                ImageFileAttachment = ImageFileAttachments[0];
                        }
        }
开发者ID:HenroOnline,项目名称:DotNet-Auction,代码行数:25,代码来源:AuctionItemDetailModel.cs

示例7: Alter

 /// <summary>
 /// 输出Alter
 /// </summary>
 /// <param name="msg"></param>
 /// <returns></returns>
 protected virtual void Alter(string msg)
 {
     var str = new StringBuilder("<script type=\"text/javascript\">");
     str.AppendFormat("alert('{0}');",msg);
     str.Append("</script>");
     TempData["alter"] = new MvcHtmlString(str.ToString());
 }
开发者ID:Cotide,项目名称:Cotide.DomainDrivenDesign,代码行数:12,代码来源:BaseController.cs

示例8: Copyright

 public static MvcHtmlString Copyright(
     this HtmlHelper htmlHelper,
     string text)
 {
     MvcHtmlString result = new MvcHtmlString("Copyright " + DateTime.Now.Year + " " + text);
     return result;
 }
开发者ID:khduong,项目名称:IntroMvcDemo,代码行数:7,代码来源:CopyrightHelper.cs

示例9: BuildBreadcrumbs

        public List<Breadcrumb> BuildBreadcrumbs(RequestContext context)
        {
            var result = new List<Breadcrumb>();
            var html = GetHtmlHelper(context);

            var breadcrumbs = BuildTree(context);
            for (int i = 0; i < breadcrumbs.Count; i++) {
                var data = breadcrumbs[i].Data;
                if (!data.IsVisible) {
                    break;
                }

                MvcHtmlString link = null;
                if (data.IsClickable) {
                    if (i == 0) {
                        link = new MvcHtmlString(string.Format("<a href='/'>{0}</a>", data.Title));
                    }
                    else {
                        var routeValues = data.RouteValues;
                        foreach (string key in data.QueryString.Keys) {
                            routeValues[key] = data.QueryString[key];
                        }
                        link = html.ActionLink(data.Title, data.Action, data.Controller, routeValues, null);
                    }
                }

                data.QueryString.Clear();
                data.RouteValues.Clear();
                result.Add(new Breadcrumb { Name = data.Title, IsDynamic = breadcrumbs[i].IsDynamic, Url = link });
            }
            return result;
        }
开发者ID:jobert83,项目名称:MvcBreadcrumbs,代码行数:32,代码来源:Generator.cs

示例10: RenderTemplates

        public static MvcHtmlString RenderTemplates(this HtmlHelper helper, string virtualPath)
        {
            var absolutePath = HttpContext.Current.Request.MapPath(virtualPath);
            var cacheKey = string.Format(CACHE_KEY, "Templates", absolutePath);

            if (HttpRuntime.Cache[absolutePath] == null)
            {
                lock (_templatesLock)
                {
                    if (HttpRuntime.Cache[absolutePath] == null)
                    {
                        var directoryInfo = new DirectoryInfo(absolutePath);

                        if (directoryInfo.Exists)
                        {
                            var dependencyList = new List<string>();
                            var depth = 0;
                            var templateContent = new MvcHtmlString(GetDirectoryTemplatesRecursive(directoryInfo, ref depth, dependencyList));

                            HttpRuntime.Cache.Insert(absolutePath, templateContent, new CacheDependency(dependencyList.ToArray()));
                        }
                        else
                        {
                            throw new Exception(string.Format("The template folder '{0}' could not be found.", absolutePath));
                        }
                    }
                }
            }

            return HttpRuntime.Cache[absolutePath] as MvcHtmlString;
        }
开发者ID:syamaner,项目名称:ember-sandbox,代码行数:31,代码来源:EmberHtmlHelper.cs

示例11: Resolve

        public static string Resolve(MvcHtmlString content, int characters = 500)
        {
            string stripped;
            resolve(content, characters, out stripped);

            return stripped;
        }
开发者ID:Gutek,项目名称:MovingScrewdriver,代码行数:7,代码来源:DescriptionResolver.cs

示例12: WrapedInLabel

        public static HtmlString WrapedInLabel(this HtmlHelper helper, MvcHtmlString @object, object labelAttribtues = null, object wrappedObjectAttribtues = null)
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder wrappedObjectSb = new StringBuilder();
            Match match = Regex.Match(@object.ToHtmlString(), @"id=""(?<ID>\w+)""");
            if (match.Success)
            {
                sb.AppendFormat("<label ");
                if (labelAttribtues != null)
                {
                    PropertyInfo[] propertyInfos = labelAttribtues.GetType().GetProperties();
                    foreach (PropertyInfo propertyInfo in propertyInfos)
                    {
                        sb.AppendFormat(@"{0}=""{1}"">", propertyInfo.Name, propertyInfo.GetValue(labelAttribtues, null));
                    }
                }
                sb.AppendFormat(@"<strong>{0}</strong>", match.Groups["ID"].Value);

                wrappedObjectSb.Append(@object.ToHtmlString());
                int firstWhiteSpace = @object.ToHtmlString().IndexOf(" ");

                if (wrappedObjectAttribtues != null)
                {
                    PropertyInfo[] propertyInfos = wrappedObjectAttribtues.GetType().GetProperties();
                    foreach (PropertyInfo propertyInfo in propertyInfos)
                    {
                        wrappedObjectSb.Insert(firstWhiteSpace,String.Format(@" {0}=""{1}"" ", propertyInfo.Name, propertyInfo.GetValue(wrappedObjectAttribtues, null)));
                    }
                }

                sb.AppendFormat("{0}", wrappedObjectSb);
                sb.Append("</label>");
            }
            return new HtmlString(sb.ToString());
        }
开发者ID:michal-franc,项目名称:ElearnServices,代码行数:35,代码来源:LabelWrap.cs

示例13: IsNullOrEmpty

 public static bool IsNullOrEmpty(MvcHtmlString value)
 {
     if (value != null)
     return value._value.Length == 0;
       else
     return true;
 }
开发者ID:brandontruong,项目名称:HTPBP,代码行数:7,代码来源:MvcHtmlString.cs

示例14: RenderEntity

 /// <summary>
 /// Render an entity (Component Presentation)
 /// </summary>
 /// <param name="item">The Component Presentation object</param>
 /// <param name="helper">The HTML Helper</param>
 /// <param name="containerSize">The size of the containing element (in grid units)</param>
 /// <param name="excludedItems">A list of view names, if the Component Presentation maps to one of these, it is skipped.</param>
 /// <returns>The rendered content</returns>
 public override MvcHtmlString RenderEntity(object item, HtmlHelper helper, int containerSize = 0, List<string> excludedItems = null)
 {
     var cp = item as IComponentPresentation;
     var mvcData = ContentResolver.ResolveMvcData(cp);
     if (cp != null && (excludedItems == null || !excludedItems.Contains(mvcData.ViewName)))
     {
         var parameters = new RouteValueDictionary();
         int parentContainerSize = helper.ViewBag.ContainerSize;
         if (parentContainerSize == 0)
         {
             parentContainerSize = SiteConfiguration.MediaHelper.GridSize;
         }
         if (containerSize == 0)
         {
             containerSize = SiteConfiguration.MediaHelper.GridSize;
         }
         parameters["containerSize"] = (containerSize * parentContainerSize) / SiteConfiguration.MediaHelper.GridSize;
         parameters["entity"] = cp;
         parameters["area"] = mvcData.ControllerAreaName;
         foreach (var key in mvcData.RouteValues.Keys)
         {
             parameters[key] = mvcData.RouteValues[key];
         }
         MvcHtmlString result = helper.Action(mvcData.ActionName, mvcData.ControllerName, parameters);
         if (WebRequestContext.IsPreview)
         {
             result = new MvcHtmlString(TridionMarkup.ParseEntity(result.ToString()));
         }
         return result;
     }
     return null;
 }
开发者ID:MrSnowflake,项目名称:tri,代码行数:40,代码来源:DD4TRenderer.cs

示例15: ImageLink

        public static MvcHtmlString ImageLink(
            this HtmlHelper Helper,
            string ActionName,
            string ControllerName,
            object RouteValues,
            object LinkAttributes,
            string ImageSrc,
            string ImageAlt,
            object ImageAttributes)
        {
            TagBuilder imgTag = new TagBuilder("img");
            imgTag.Attributes.Add("src", Helper.Encode(ImageSrc));
            imgTag.Attributes.Add("alt", Helper.Encode(ImageAlt));
            imgTag.MergeAttributes((IDictionary<string, object>)ImageAttributes, true);

            UrlHelper urlHelper = ((Controller)Helper.ViewContext.Controller).Url;
            var url = urlHelper.Action(ActionName, ControllerName, RouteValues);

            TagBuilder linkTag = new TagBuilder("a");
            linkTag.MergeAttribute("href", url);
            linkTag.InnerHtml = imgTag.ToString(TagRenderMode.SelfClosing);
            linkTag.MergeAttributes((IDictionary<string, object>)LinkAttributes, true);

            MvcHtmlString html = new MvcHtmlString(linkTag.ToString());
            return html;
        }
开发者ID:CineGlassDev,项目名称:CineGlassNextGen,代码行数:26,代码来源:HtmlHelpers.cs


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