Ejemplo n.º 1
0
 public static MvcHtmlString ActionHtmlLink(this System.Web.Mvc.AjaxHelper ajax, string htmlText, string actionName, string controllerName, object routeValues,
                                            AjaxOptions ajaxOptions, object htmlAttributes)
 {
     return(MvcHtmlString.Create(ajax.ActionLink("[*AnchorText]", actionName, controllerName, routeValues, ajaxOptions, htmlAttributes)
                                 .ToString().Replace("[*AnchorText]", htmlText)
                                 ));
 }
Ejemplo n.º 2
0
   public static MvcHtmlString DeleteLink(AjaxHelper ajaxHelper, string linkText, string actionName, object routeValues)
 {
     return ajaxHelper.ActionLink(linkText, actionName, routeValues, new AjaxOptions
     {
         Confirm = "Are you sure you want to delete this item?",
         HttpMethod = "DELETE",
         OnSuccess = "function() { window.location.reload(); }"
     });
 }
        private static MvcHtmlString ComposeImageActionLink(AjaxHelper helper, string imageUrl, string altText,
		                                                    string actionName, string controllerName, object routeValues,
		                                                    AjaxOptions ajaxOptions, object htmlAttributes = null)
        {
            var builder = new TagBuilder("img");
            builder.MergeAttribute("src", imageUrl);
            builder.MergeAttribute("alt", altText);
            string link =
                helper.ActionLink("[replaceme]", actionName, controllerName, routeValues, ajaxOptions, htmlAttributes).ToHtmlString();
            return new MvcHtmlString(link.Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing)));
        }
Ejemplo n.º 4
0
        public static string ImageActionLink(this AjaxHelper helper, string imageUrl, string altText, string actionName, object routeValues, AjaxOptions ajaxOptions)
        {
            var builder = new TagBuilder("img");

            builder.MergeAttribute("src", imageUrl);
            builder.MergeAttribute("alt", altText);
            builder.MergeAttribute("title", altText);
            var link = helper.ActionLink("[replaceme]", actionName, routeValues, ajaxOptions);

            return(link.ToString().Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing)));
        }
Ejemplo n.º 5
0
        public static MvcHtmlString RawActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes)
        {
            ajaxOptions.OnBegin    = string.IsNullOrEmpty(ajaxOptions.OnBegin) ? "LoadLoading();" : string.Format("{0} {1}", "LoadLoading();", ajaxOptions.OnBegin);
            ajaxOptions.OnComplete = ajaxOptions.OnComplete == null ? "UnloadLoading();" : string.Concat(ajaxOptions.OnComplete, "UnloadLoading();");
            ajaxOptions.OnFailure  = ajaxOptions.OnFailure == null ? "UnloadLoading();" : string.Concat(ajaxOptions.OnFailure, "UnloadLoading();");

            var repID = Guid.NewGuid().ToString();
            var lnk   = ajaxHelper.ActionLink(repID, actionName, controllerName, routeValues, ajaxOptions, htmlAttributes);

            return(MvcHtmlString.Create(lnk.ToString().Replace(repID, linkText)));
        }
Ejemplo n.º 6
0
        public static MvcHtmlString DeleteLink <TModel>(this AjaxHelper <TModel> ajaxHelper, String linkText, String actionName, String controllerName = null, Object routeValues = null, IDictionary <String, Object> htmlAttributes = null)
        {
            var ajaxOptDelete = new AjaxOptions
            {
                Confirm    = "Are you sure you want to delete this item?",
                HttpMethod = "DELETE",
                OnSuccess  = "function() { window.location.reload(); }"
            };

            return(ajaxHelper.ActionLink(linkText, actionName, controllerName, routeValues, ajaxOptDelete, htmlAttributes));
        }
Ejemplo n.º 7
0
 public static MvcHtmlString ImageActionLink(this AjaxHelper ajaxHelper, String imageUrl, String altText, String actionName, Object routeValues, AjaxOptions ajaxOptions)
 {
     using (var stringWriter = new StringWriter())
         using (var htmlWriter = new HtmlTextWriter(stringWriter))
         {
             var linkHtml = ajaxHelper.ActionLink("[LinkText]", actionName, routeValues, ajaxOptions).ToHtmlString();
             htmlWriter.AddAttribute(HtmlTextWriterAttribute.Src, imageUrl);
             htmlWriter.AddAttribute(HtmlTextWriterAttribute.Alt, altText);
             htmlWriter.RenderBeginTag(HtmlTextWriterTag.Img);
             htmlWriter.RenderEndTag();
             return(MvcHtmlString.Create(linkHtml.Replace("[LinkText]", stringWriter.ToString())));
         }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Create full captcha
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        internal static MvcHtmlString GenerateFullCaptcha(HtmlHelper htmlHelper, int length)
        {
            var encryptorModel = GetEncryptorModel();
            var captchaText = RandomText.Generate(length);
            var encryptText = Encryption.Encrypt(captchaText, encryptorModel.Password, encryptorModel.Salt);

            var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
            var url = urlHelper.Action("Create", "CaptchaImage", new { encryptText});

            var ajax = new AjaxHelper(htmlHelper.ViewContext, htmlHelper.ViewDataContainer);
            var refresh = ajax.ActionLink("Refresh", "NewCaptcha", "CaptchaImage", new {l = length},
                                          new AjaxOptions { UpdateTargetId = "CaptchaDeText", OnSuccess = "Success" });

            return MvcHtmlString.Create(string.Format(CaptchaFormat, url, htmlHelper.Hidden("CaptchaDeText", encryptText)) +
                                         refresh.ToHtmlString() + " <br/>Enter symbol: " +
                                        htmlHelper.TextBox("CaptchaInputText"));
        }
        public static MvcHtmlString CustomActionLink(this AjaxHelper ajax,
            string linkText,
            string actionName,
            string controllerName,
          //  RouteValueDictionary routeValues=null, 
            object routeValues=null,
            object htmlAttributes = null,
            string updateTargetId = "content",
            string loadingElementId = "loading-indicator"
            )
        {
            //TagBuilder tag = new TagBuilder("a");
            //tag.MergeAttribute("data-ajax","true");
            //tag.MergeAttribute("data-ajax-mode", "replace");
            //tag.MergeAttribute("data-ajax-update", updateTargetId);
            //tag.MergeAttribute("data-ajax-loading", loadingElementId);
            //string url = UrlHelper.GenerateUrl("Default", actionName, controllerName, routeValues, html.RouteCollection,
            //html.ViewContext.RequestContext, true);//RouteTable.Routes
            //tag.MergeAttribute("href", url);
            //tag.InnerHtml = linkText;
            //return new MvcHtmlString(tag.ToString());
            AjaxOptions ajaxOptions = new AjaxOptions()
            {
                LoadingElementId = loadingElementId,
                UpdateTargetId = updateTargetId
            };

            AjaxHelper ajaxHelper = new AjaxHelper(ajax.ViewContext, ajax.ViewDataContainer);
            return ajaxHelper.ActionLink(linkText, actionName, controllerName, routeValues, ajaxOptions, htmlAttributes);

            //var ajaxAttributes = new
            //{
            //    "data-ajax" = "true",
            //    data-ajax-mode = "replace",
            //    data-ajax-update = updateTargetId,
            //    data-ajax-loading = loadingElementId
            //};

            //return html.ActionLink(linkText, actionName, controllerName, routeValues).;
        }
Ejemplo n.º 10
0
 public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, Task <ActionResult> taskResult, AjaxOptions ajaxOptions, IDictionary <string, object> htmlAttributes)
 {
     return(ajaxHelper.ActionLink(linkText, taskResult.Result, ajaxOptions, htmlAttributes));
 }
Ejemplo n.º 11
0
 public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, Task <ActionResult> taskResult, AjaxOptions ajaxOptions)
 {
     return(ajaxHelper.ActionLink(linkText, taskResult.Result, ajaxOptions));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Create full captcha
 /// </summary>
 /// <param name="htmlHelper"></param>
 /// <param name="text"></param>
 /// <param name="inputText"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 internal static MvcHtmlString GenerateFullCaptcha(HtmlHelper htmlHelper, string text, string inputText, int length)
 {
     var encryptorModel = GetEncryptorModel();
     var captchaText = RandomText.Generate(length);
     var encryptText = GetEncryption().Encrypt(captchaText, encryptorModel.Password, encryptorModel.Salt);
     var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
     var url = urlHelper.Action("Create", "CaptchaImage", new { encryptText });
     var ajax = new AjaxHelper(htmlHelper.ViewContext, htmlHelper.ViewDataContainer);
     var refresh = ajax.ActionLink(text, "NewCaptcha", "CaptchaImage", new { l = length },
                                                                 new AjaxOptions { UpdateTargetId = "CaptchaDeText", OnSuccess = "Success" });
     string tgs = "<div style=\"float: left; margin-top: 5px;\">" + refresh.ToHtmlString() + " <br/>" + inputText + "<br/>" +
         htmlHelper.TextBox("CaptchaInputText", "", new { data_val_required = "*", data_val = "true", data_val_length_min = "5", data_val_length_max = "5", data_val_length = "*" }) +
         htmlHelper.ValidationMessage("CaptchaInputText") + "</div>";
     return MvcHtmlString.Create(tgs + string.Format(CaptchaFormat, url, htmlHelper.Hidden("CaptchaDeText", encryptText)));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 生成分页栏上的菜单。
        /// </summary>
        /// <param name="html">HTML呈现器</param>
        /// <param name="pageCount">总页数</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="linkText">菜单文本</param>
        /// <param name="actionName">重定向操作名称</param>
        /// <param name="controllerName">重定向控制器名称</param>
        /// <param name="routeValues">路由参数</param>
        /// <param name="ajaxOptions">Ajax选项设置</param>
        /// <returns>HTML片段</returns>
        private static string CreateActionLink(
            this HtmlHelper html,
            int pageCount,
            int pageIndex,
            string linkText,
            string actionName,
            string controllerName,
            RouteValueDictionary routeValues,
            AjaxOptions ajaxOptions)
        {
            if (routeValues.ContainsKey(PagerRouteName))
            {
                routeValues[PagerRouteName] = pageIndex;
            }
            else
            {
                routeValues.Add(PagerRouteName, pageIndex);
            }

            IHtmlString link;
            var currentIndex = html.GetCurrentIndex();
            currentIndex = currentIndex > pageCount ? pageCount : currentIndex;

            if (currentIndex == pageIndex)
            {
                return
                    $"<li class=\"active\"><a href=\"#\">{pageIndex} <span class=\"sr-only\">(current)</span></a></li>";
            }

            if (ajaxOptions != null)
            {
                var ajax = new AjaxHelper(html.ViewContext, html.ViewDataContainer);

                link = ajax.ActionLink(linkText, actionName, controllerName, routeValues, ajaxOptions, null);
            }
            else
            {
                link = html.ActionLink(linkText, actionName, controllerName, routeValues, null);
            }

            return "<li>" + link.ToHtmlString() + "</li>";
        }