本文整理汇总了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;
}
示例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'> </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> </label>" : label.ToString();
//l.InnerHtml += input.ToString();
p.InnerHtml += html;
}
return this;
}
示例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());
}
示例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;
}
示例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;
}
示例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];
}
}
示例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());
}
示例8: Copyright
public static MvcHtmlString Copyright(
this HtmlHelper htmlHelper,
string text)
{
MvcHtmlString result = new MvcHtmlString("Copyright " + DateTime.Now.Year + " " + text);
return result;
}
示例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;
}
示例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;
}
示例11: Resolve
public static string Resolve(MvcHtmlString content, int characters = 500)
{
string stripped;
resolve(content, characters, out stripped);
return stripped;
}
示例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());
}
示例13: IsNullOrEmpty
public static bool IsNullOrEmpty(MvcHtmlString value)
{
if (value != null)
return value._value.Length == 0;
else
return true;
}
示例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;
}
示例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;
}