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


C# AjaxOptions.ToUnobtrusiveHtmlAttributes方法代码示例

本文整理汇总了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());
        }
开发者ID:kibiluzbad,项目名称:Ifa,代码行数:9,代码来源:IfaHelper.cs

示例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);
 }
开发者ID:Slicksim,项目名称:Ajax-Playground,代码行数:10,代码来源:AjaxExtensions.cs

示例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;
 }
开发者ID:lequangphuoc,项目名称:SPager,代码行数:13,代码来源:SPagerExtensions.cs

示例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);
 }
开发者ID:sandipghosh,项目名称:NJFairground,代码行数:17,代码来源:AjaxExtensions.cs

示例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);
        }
开发者ID:glacasa,项目名称:MvcHtmlLink,代码行数:22,代码来源:HtmlLink.cs

示例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;
		}
开发者ID:CanoCheng,项目名称:PagedList,代码行数:22,代码来源:PagedListRenderOptions.cs

示例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);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:21,代码来源:AjaxExtensions.cs

示例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;
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:35,代码来源:AjaxExtensions.cs

示例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 ) );
        }
开发者ID:john-t-white,项目名称:Hex,代码行数:20,代码来源:BeginLinkExtensions.cs

示例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);
        }
开发者ID:regiuskornel,项目名称:T4CSS-Sprite,代码行数:96,代码来源:SpriteButtonHelper.cs


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