本文整理汇总了C#中System.Web.Mvc.MvcHtmlString.ToHtmlString方法的典型用法代码示例。如果您正苦于以下问题:C# MvcHtmlString.ToHtmlString方法的具体用法?C# MvcHtmlString.ToHtmlString怎么用?C# MvcHtmlString.ToHtmlString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.MvcHtmlString
的用法示例。
在下文中一共展示了MvcHtmlString.ToHtmlString方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: DefaultPagingHtml
public static string DefaultPagingHtml(int option, MvcHtmlString actionLink = null, bool active = false)
{
switch (option)
{
case PagingOptConst.Wrapper: return @"<ul class=""pagination"">{0}{1}{2}{3}{4}</ul>";
case PagingOptConst.FirstLastButton: return string.Format(@"<li class=""paging-first-last"">{0}</li>", actionLink.ToHtmlString());
case PagingOptConst.PrevNextButton: return string.Format(@"<li class=""paging-prev-next"">{0}</li>", actionLink.ToHtmlString());
case PagingOptConst.NumberButton: return string.Format(@"<li class=""page-number {0}"">{1}</li>", active ? "paging-active" : string.Empty, actionLink.ToHtmlString());
case PagingOptConst.NoneActionString: return string.Format(@"<li class=""paging-none-action""><a href=""javascript:;"">...</a></li>");
}
return string.Empty;
}
示例3: MenuItem
public static MvcHtmlString MenuItem(this HtmlHelper helper, MvcHtmlString link, string controller)
{
var li = new TagBuilder("li");
if (helper.ViewContext.Controller.GetType().Name.ToLower() == String.Format("{0}controller", controller).ToLower())
li.Attributes.Add("class", "selected");
li.InnerHtml = link.ToHtmlString();
return new MvcHtmlString(li.ToString());
}
示例4: resolve
private static bool resolve(MvcHtmlString content, int characters, out string resolved)
{
var stripped = content == null ?
string.Empty : content.ToHtmlString().StripHtml();
if (stripped.Length > characters)
{
resolved = stripped.FirstCharacters(characters);
return true;
}
resolved = stripped;
return false;
}
示例5: HtmlHelperExtensionsImageAbsoultePathAndClassTest
public void HtmlHelperExtensionsImageAbsoultePathAndClassTest()
{
// Przekazany url
const string Url = "test.com/someimg.jpg";
// Oczekiwany tag html
var expected =
new MvcHtmlString(
"<img alt=\"" + AlternateText + "\" class=\"" + Class + "\" id=\"" + Id + "\" src=\"" + Url
+ "\" />");
// stworzenie instancji HtmlHelper
var htmlHelper = new HtmlHelper(new ViewContext(), Substitute.For<IViewDataContainer>());
// Wykonanie helpera Image
var tag = htmlHelper.Image(Id, Url, AlternateText, new { @class = Class });
// Sprawdzenie
Assert.IsInstanceOfType(tag, typeof(MvcHtmlString));
Assert.AreEqual(expected.ToHtmlString(), tag.ToHtmlString());
}
示例6: getIdFromString
private static string getIdFromString(MvcHtmlString html)
{
string raw = html.ToHtmlString();
if (raw.IndexOf("id=") == -1)
throw new ArgumentException("MVC.Controls.DatePicker can only be used for MvcHtmlString with an html-id"
+ Environment.NewLine + "[" + html.ToHtmlString() + "]");
raw = raw.Substring(raw.IndexOf("id=") + 4);
raw = raw.Substring(0, raw.IndexOf("\""));
return raw;
}
示例7: ResponsiveTd
public static MvcHtmlString ResponsiveTd(this HtmlHelper html, string label, MvcHtmlString content)
{
return new MvcHtmlString(string.Format(@"<td data-label=""{0}"">{1}</td>", label, content.ToHtmlString()));
}
示例8: EmbeddedTemplate
public static MvcHtmlString EmbeddedTemplate(EntityBase entityBase, MvcHtmlString template, string defaultString)
{
return MvcHtmlString.Create("<script type=\"template\" id=\"{0}\" data-toString=\"{2}\">{1}</script>".Formato(
entityBase.Compose(EntityBaseKeys.Template),
regex.Replace(template.ToHtmlString(), m => m.Value + "X"),
defaultString));
}
示例9: AddLine
public void AddLine(MvcHtmlString html)
{
if (!MvcHtmlString.IsNullOrEmpty(html))
sb.AppendLine(html.ToHtmlString());
}
示例10: Concat
public static MvcHtmlString Concat(this MvcHtmlString one, MvcHtmlString other)
{
if (MvcHtmlString.IsNullOrEmpty(one))
return other;
if (MvcHtmlString.IsNullOrEmpty(other))
return one;
return MvcHtmlString.Create(one.ToHtmlString() + other.ToHtmlString());
}
示例11: InnerHtml
public HtmlTag InnerHtml(MvcHtmlString html)
{
if (MvcHtmlString.IsNullOrEmpty(html))
tagBuilder.InnerHtml = null;
else
tagBuilder.InnerHtml = html.ToHtmlString();
return this;
}
示例12: HtmlHelperExtensionsImageRelativePathTest
public void HtmlHelperExtensionsImageRelativePathTest()
{
// Przekazany url
const string Url = "~/someimg.jpg";
// Oczekiwany url
const string ExpectedUrl = "/app/someimg.jpg";
// Oczekiwany tag html
var expected =
new MvcHtmlString("<img alt=\"" + AlternateText + "\" id=\"" + Id + "\" src=\"" + ExpectedUrl + "\" />");
// stworzenie instancji HtmlHelper
var htmlHelper = new HtmlHelper(new ViewContext(), Substitute.For<IViewDataContainer>());
// Mokowanie HttpContextBase
var fakeHttpContext = Substitute.ForPartsOf<HttpContextBase>();
// Ustawienie właściwośći readonly Request
// ReSharper disable once UnusedVariable
fakeHttpContext.When(x => { var get = x.Request; }).DoNotCallBase();
fakeHttpContext.Request.Returns(Substitute.ForPartsOf<HttpRequestBase>());
// Ustawienie właściwośći readonly ApplicaitonPath
// ReSharper disable once UnusedVariable
fakeHttpContext.Request.When(x => { var get = x.ApplicationPath; }).DoNotCallBase();
fakeHttpContext.Request.ApplicationPath.Returns("/app/");
// Podststawienie i wykonanie helpera Image
htmlHelper.ViewContext.HttpContext = fakeHttpContext;
var tag = htmlHelper.Image(Id, Url, AlternateText);
// Sprawdzenie
Assert.IsInstanceOfType(tag, typeof(MvcHtmlString));
Assert.AreEqual(expected.ToHtmlString(), tag.ToHtmlString());
}
示例13: GrayButton
public static MvcHtmlString GrayButton(this HtmlHelper html, MvcHtmlString content)
{
return GrayButton(html, content.ToHtmlString());
}
示例14: ReplaceNewLines
public static MvcHtmlString ReplaceNewLines(this HtmlHelper htmlHelper, MvcHtmlString str)
{
string pattern = @"\r\n|\n\r|\r|\n";
string htmlStr = str.ToHtmlString();
string result = Regex.Replace(htmlStr, pattern, " ");
StringBuilder builder = new StringBuilder();
builder.Append(result);
return MvcHtmlString.Create(builder.ToString());
}