本文整理汇总了C#中System.Web.Mvc.Ajax.AjaxOptions.ToUnobtrusiveHtmlAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# AjaxOptions.ToUnobtrusiveHtmlAttributes方法的具体用法?C# AjaxOptions.ToUnobtrusiveHtmlAttributes怎么用?C# AjaxOptions.ToUnobtrusiveHtmlAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.Ajax.AjaxOptions
的用法示例。
在下文中一共展示了AjaxOptions.ToUnobtrusiveHtmlAttributes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAjaxAttributes
public static string GetAjaxAttributes(AjaxOptions options)
{
if (null == options) return string.Empty;
var dictionary = options.ToUnobtrusiveHtmlAttributes();
return string.Join(" ", dictionary
.Select(c => string.Format("{0}={1}", c.Key, c.Value))
.ToArray());
}
示例2: BeginActionLink
public static MvcAnchor BeginActionLink(this AjaxHelper ajaxHelper, string actionName, string controllerName, RouteValueDictionary routeValues, AjaxOptions ajaxOptions, RouteValueDictionary htmlAttributes)
{
var targetUrl = UrlHelper.GenerateUrl(null, actionName, controllerName, routeValues, ajaxHelper.RouteCollection, ajaxHelper.ViewContext.RequestContext, true);
var builder = new TagBuilder("a");
builder.MergeAttributes(htmlAttributes);
builder.MergeAttribute("href", targetUrl);
builder.MergeAttributes(ajaxOptions.ToUnobtrusiveHtmlAttributes());
ajaxHelper.ViewContext.Writer.Write(builder.ToString(TagRenderMode.StartTag));
return new MvcAnchor(ajaxHelper.ViewContext);
}
示例3: GenerateLink
private static TagBuilder GenerateLink(int page, Func<int,string> generateUrl, bool active, string linkText, AjaxOptions ajaxOptions)
{
var li = new TagBuilder("li");
if (active)
li.MergeAttribute("class", "active");
var a = new TagBuilder("a");
a.MergeAttribute("href", active ? "javascript:void()" : generateUrl(page));
a.SetInnerText(linkText);
if(ajaxOptions != null)
a.MergeAttributes<string, object>(ajaxOptions.ToUnobtrusiveHtmlAttributes());
li.InnerHtml = a.ToString();
return li;
}
示例4: GenerateLink
private static string GenerateLink(
this AjaxHelper ajaxHelper,
string linkText,
string targetUrl,
AjaxOptions ajaxOptions,
IDictionary<string, object> htmlAttributes
)
{
var a = new TagBuilder("a")
{
InnerHtml = linkText
};
a.MergeAttributes<string, object>(htmlAttributes);
a.MergeAttribute("href", targetUrl);
a.MergeAttributes<string, object>(ajaxOptions.ToUnobtrusiveHtmlAttributes());
return a.ToString(TagRenderMode.Normal);
}
示例5: GenerateLink
private string GenerateLink(string targetUrl, IDictionary<string, object> htmlAttributes, AjaxOptions ajaxOptions)
{
TagBuilder tag = new TagBuilder("a");
tag.MergeAttributes(htmlAttributes);
tag.MergeAttribute("href", targetUrl);
if (ajaxOptions != null)
{
if (_viewContext.UnobtrusiveJavaScriptEnabled)
{
tag.MergeAttributes(ajaxOptions.ToUnobtrusiveHtmlAttributes());
}
else
{
tag.MergeAttribute("onclick", GenerateAjaxScript(ajaxOptions, LinkOnClickFormat));
}
//tag.MergeAttributes(ajaxOptions.ToUnobtrusiveHtmlAttributes());
}
return tag.ToString(TagRenderMode.StartTag);
}
示例6: EnableUnobtrusiveAjaxReplacing
/// <summary>
/// Enables ASP.NET MVC's unobtrusive AJAX feature. An XHR request will retrieve HTML from the clicked page and replace the innerHtml of the provided element ID.
/// </summary>
/// <param name="options">The preferred Html.PagedList(...) style options.</param>
/// <param name="ajaxOptions">The ajax options that will put into the link</param>
/// <returns>The PagedListRenderOptions value passed in, with unobtrusive AJAX attributes added to the page links.</returns>
public static PagedListRenderOptions EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions options, AjaxOptions ajaxOptions)
{
options.FunctionToTransformEachPageLink = (liTagBuilder, aTagBuilder) =>
{
var liClass = liTagBuilder.Attributes.ContainsKey("class") ? liTagBuilder.Attributes["class"] ?? "" : "";
if (ajaxOptions != null && !liClass.Contains("disabled") && !liClass.Contains("active"))
{
foreach (var ajaxOption in ajaxOptions.ToUnobtrusiveHtmlAttributes())
aTagBuilder.Attributes.Add(ajaxOption.Key, ajaxOption.Value.ToString());
}
liTagBuilder.InnerHtml = aTagBuilder.ToString();
return liTagBuilder;
};
return options;
}
示例7: GenerateLink
private static string GenerateLink(AjaxHelper ajaxHelper, string linkText, string targetUrl, AjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes)
{
TagBuilder tag = new TagBuilder("a")
{
InnerHtml = HttpUtility.HtmlEncode(linkText)
};
tag.MergeAttributes(htmlAttributes);
tag.MergeAttribute("href", targetUrl);
if (ajaxHelper.ViewContext.UnobtrusiveJavaScriptEnabled)
{
tag.MergeAttributes(ajaxOptions.ToUnobtrusiveHtmlAttributes());
}
else
{
tag.MergeAttribute("onclick", GenerateAjaxScript(ajaxOptions, LinkOnClickFormat));
}
return tag.ToString(TagRenderMode.Normal);
}
示例8: FormHelper
private static MvcForm FormHelper(this AjaxHelper ajaxHelper, string formAction, AjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes)
{
TagBuilder builder = new TagBuilder("form");
builder.MergeAttributes(htmlAttributes);
builder.MergeAttribute("action", formAction);
builder.MergeAttribute("method", "post");
ajaxOptions = GetAjaxOptions(ajaxOptions);
if (ajaxHelper.ViewContext.UnobtrusiveJavaScriptEnabled)
{
builder.MergeAttributes(ajaxOptions.ToUnobtrusiveHtmlAttributes());
}
else
{
builder.MergeAttribute("onclick", FormOnClickValue);
builder.MergeAttribute("onsubmit", GenerateAjaxScript(ajaxOptions, FormOnSubmitFormat));
}
if (ajaxHelper.ViewContext.ClientValidationEnabled)
{
// forms must have an ID for client validation
builder.GenerateId(ajaxHelper.ViewContext.FormIdGenerator());
}
ajaxHelper.ViewContext.Writer.Write(builder.ToString(TagRenderMode.StartTag));
MvcForm theForm = new MvcForm(ajaxHelper.ViewContext);
if (ajaxHelper.ViewContext.ClientValidationEnabled)
{
ajaxHelper.ViewContext.FormContext.FormId = builder.Attributes["id"];
}
return theForm;
}
示例9: GenerateLinkInternal
private static void GenerateLinkInternal( this AjaxHelper ajaxHelper, string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, AjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes, bool includeImplicitMvcValues )
{
string url = UrlHelper.GenerateUrl( routeName, actionName, controllerName, protocol, hostName, fragment, routeValues, ajaxHelper.RouteCollection, ajaxHelper.ViewContext.RequestContext, includeImplicitMvcValues );
TagBuilder linkTagBuilder = new TagBuilder( "a" );
linkTagBuilder.MergeAttributes( htmlAttributes );
linkTagBuilder.MergeAttribute( HtmlAttributes.Href, url );
if( !ajaxHelper.ViewContext.UnobtrusiveJavaScriptEnabled )
{
string onClickScript = string.Format( CultureInfo.InvariantCulture, LINK_ON_CLICK_FORMAT, BeginLinkExtensions.InvokeAjaxOptionsToJavascriptString( ajaxOptions ) );
linkTagBuilder.MergeAttribute( HtmlAttributes.Events.OnClick, onClickScript );
}
else
{
linkTagBuilder.MergeAttributes<string, object>( ajaxOptions.ToUnobtrusiveHtmlAttributes() );
}
ajaxHelper.ViewContext.Writer.Write( linkTagBuilder.ToString( TagRenderMode.StartTag ) );
}
示例10: GenerateLinkInternal
private static string GenerateLinkInternal(RequestContext requestContext,
RouteCollection routeCollection, string icon,
ButtonMode status, string linkText, string routeName,
string actionName, string controllerName,
RouteValueDictionary routeValues,
IDictionary<string, object> htmlAttributes,
string iconvariantclass,
AjaxHelper ajaxHelper, AjaxOptions ajaxOptions)
{
//Make the link
string targetUrl = UrlHelper.GenerateUrl(routeName, actionName,
controllerName, null, null, null, routeValues, routeCollection,
requestContext, false);
//Tesing parameters
if ((status & ButtonMode.IconOnly) != 0 && string.IsNullOrEmpty(icon))
throw new Exception("Only icon button without icon, how?");
//Prepare button caption.
string caption = HttpUtility.HtmlEncode(linkText);
bool disabled = (status & ButtonMode.Disabled) != 0;
//Insert caption into a <span> with own CSS class
TagBuilder captionTag = null;
if ((status & ButtonMode.IconOnly) == 0)
{
captionTag = new TagBuilder("span") { InnerHtml = caption };
captionTag.AddCssClass("t4button-text");
}
//Also insert icon into a <span>. Link this main CSS class which made by the T4 sprite-generator.
//include unique icon name from helper method parameter
TagBuilder iconTag = null;
if (!string.IsNullOrEmpty(icon))
{
iconTag = new TagBuilder("span");
iconTag.AddCssClass("t4icon " + IconDefaultClass + " " + icon);
if (disabled)
iconTag.AddCssClass(IconDisabledClass);
if (!string.IsNullOrEmpty(iconvariantclass))
iconTag.AddCssClass(iconvariantclass);
}
//Making a wrapper around the caption and icon
//Disabled button wil wrap a <div>. And <a> tag for normal button status
TagBuilder buttonTag = new TagBuilder(disabled ? "div" : "a");
//rendering icon and caption <span> into wrapper tag
if (iconTag == null)
buttonTag.InnerHtml = captionTag.ToString(TagRenderMode.Normal);
else if (captionTag == null)
buttonTag.InnerHtml = iconTag.ToString(TagRenderMode.Normal);
else
buttonTag.InnerHtml = iconTag.ToString(TagRenderMode.Normal)
+ captionTag.ToString(TagRenderMode.Normal);
//another attributes can arrive from helper method parameter
buttonTag.MergeAttributes(htmlAttributes);
buttonTag.Attributes.Add("role", "button");
if (disabled)
{
buttonTag.Attributes.Add("aria-disabled", "true");
//In 'disabled' status adding the default 'disbled' CSS class (we provided in .CssClassName= "disabled" in variant definition)
buttonTag.AddCssClass(IconDisabledClass);
}
else
{
//URL for <a> tag
buttonTag.MergeAttribute("href", targetUrl);
buttonTag.Attributes.Add("aria-disabled", "false");
//If this is a Ajax helper call, will include all unobtrusive attributes.
//This is all differences between Html.ActionLink and Ajax.ActionLink.
if (ajaxHelper != null && ajaxHelper.ViewContext.UnobtrusiveJavaScriptEnabled)
buttonTag.MergeAttributes(ajaxOptions.ToUnobtrusiveHtmlAttributes());
}
//Parametrizing the title attribute
if ((status & ButtonMode.IconOnly) != 0)
{
buttonTag.AddCssClass("t4button-icon-only");
buttonTag.Attributes.Add("title", caption);
}
else
{
buttonTag.AddCssClass(iconTag == null ? "t4button-text-only" : "t4button-text-icon");
if ((status & ButtonMode.ShowTitle) != 0)
buttonTag.Attributes.Add("title", caption);
}
buttonTag.AddCssClass("t4button");
//Rendering all
return buttonTag.ToString(TagRenderMode.Normal);
}