本文整理汇总了C#中System.Web.Mvc.HtmlHelper.AttributeEncode方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.AttributeEncode方法的具体用法?C# HtmlHelper.AttributeEncode怎么用?C# HtmlHelper.AttributeEncode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper.AttributeEncode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRegisteredLinks
public MvcHtmlString GetRegisteredLinks(HtmlHelper html) {
var urlHelper = new UrlHelper(html.ViewContext.RequestContext, html.RouteCollection);
var sb = new StringBuilder();
foreach (var feed in _feeds) {
var linkUrl = feed.IsExternal ?
feed.ExternalUrl :
urlHelper.RouteUrl(feed.RouteValues);
sb.Append("\r\n<link rel=\"alternate\" type=\"application/" +
feed.Format.ToLowerInvariant() + "+xml\"");
if (!string.IsNullOrEmpty(feed.Title)) {
sb.Append(" title=\"" + html.AttributeEncode(feed.Title) + "\"");
}
sb.Append(" href=\"" + html.AttributeEncode(linkUrl) + "\"/>");
}
return MvcHtmlString.Create(sb.ToString());
}
示例2: GetRegisteredLinks
public MvcHtmlString GetRegisteredLinks(HtmlHelper html) {
var urlHelper = new UrlHelper(html.ViewContext.RequestContext, html.RouteCollection);
var sb = new StringBuilder();
foreach (var link in _links) {
var linkUrl = String.IsNullOrWhiteSpace(link.Url) ? urlHelper.RouteUrl(link.RouteValues) : link.Url;
sb.Append("\r\n");
sb.Append(@"<link rel=""alternate"" type=""application/rss+xml""");
if (!string.IsNullOrEmpty(link.Title)) {
sb
.Append(@" title=""")
.Append(html.AttributeEncode(link.Title))
.Append(@"""");
}
sb.Append(@" href=""")
.Append(html.AttributeEncode(linkUrl))
.AppendLine(@""" />");
}
return MvcHtmlString.Create(sb.ToString());
}
示例3: GetLinks
public MvcHtmlString GetLinks(HtmlHelper html)
{
var sb = new StringBuilder();
foreach (var link in _links) {
sb.Append("\r\n");
sb.Append(@"<link");
if (!string.IsNullOrEmpty(link.Rel)) {
sb
.Append(@" rel=""")
.Append(html.AttributeEncode(link.Rel))
.Append(@"""");
}
if (!string.IsNullOrEmpty(link.Type)) {
sb
.Append(@" type=""")
.Append(html.AttributeEncode(link.Type))
.Append(@"""");
}
if (!string.IsNullOrEmpty(link.Title)) {
sb
.Append(@" title=""")
.Append(html.AttributeEncode(link.Title))
.Append(@"""");
}
if (!string.IsNullOrEmpty(link.Href)) {
sb
.Append(@" href=""")
.Append(html.AttributeEncode(link.Href))
.Append(@"""");
}
sb.Append(@" />");
}
return MvcHtmlString.Create(sb.ToString());
}
示例4: CreateNonceAttribute
private static HtmlString CreateNonceAttribute(HtmlHelper helper, string nonce)
{
var sb = "nonce=\"" + helper.AttributeEncode(nonce) + "\"";
return new HtmlString(sb);
}
示例5: GetValue
public static string GetValue(HtmlHelper helper, object item, DataColumnOptions field)
{
var r = string.Empty;
if (field.EditorType == DataColumnEditorTypes.Image)
{
var col = field as ImageColumnOptions;
var valUrl = InspectDataFormat(item, field, col.ImageUrlFormat);
if (valUrl == null)
return r;
r += "<img src='" + valUrl + "'";
if (col.ImageSize.Height > 0)
r += " height='" + helper.AttributeEncode(col.ImageSize.Height.ToString()) + "'";
if (col.ImageSize.Width > 0)
r += " width='" + helper.AttributeEncode(col.ImageSize.Width.ToString()) + "'";
r += "/>";
}
else if (field.EditorType == DataColumnEditorTypes.Link)
{
var col = field as LinkColumnOptions;
var valUrl = InspectDataFormat(item, field, col.NavigateUrlFormat);
if (valUrl == null)
return r;
r += "<a href='" + valUrl + "'";
if (!string.IsNullOrWhiteSpace(col.Target))
r += " target='" + col.Target + "'";
r += ">" + col.Caption + "</a>";
}
else // LABEL VE HTMLLABEL
{
var val = InspectDataFormat(item, field);
if (val == null)
return r;
if (val.GetType().FullName == "System.Boolean")
{
bool bVal;
if (bool.TryParse(val.ToString(), out bVal))
{
r += "<input type='checkbox' disabled='disabled' value='" + bVal + "'";
if (bVal)
r += " checked='checked'";
r += "/>";
}
else r = helper.Encode(val);
}
else if (val.GetType().FullName.IndexOf("System.DateTime") > -1)
{
DateTime bVal;
r = helper.Encode(DateTime.TryParse(val.ToString(), out bVal) ? bVal.ToString(field.Format) : val);
}
else if (val.GetType().FullName.IndexOf("System.Int32") > -1)
{
int bVal;
r = helper.Encode(int.TryParse(val.ToString(), out bVal) ? bVal.ToString(field.Format) : val);
}
else if (val.GetType().FullName.IndexOf("System.Decimal") > -1)
{
decimal bVal;
r = helper.Encode(decimal.TryParse(val.ToString(), out bVal) ? bVal.ToString(field.Format) : val);
}
else
{
r = field.EditorType == DataColumnEditorTypes.Label ? helper.Encode(val.ToString()) : val.ToString();
}
}
return r;
}