public void InsertionModeToString() { // Act & Assert Assert.AreEqual(AjaxExtensions.InsertionModeToString(InsertionMode.Replace), "Sys.Mvc.InsertionMode.replace"); Assert.AreEqual(AjaxExtensions.InsertionModeToString(InsertionMode.InsertAfter), "Sys.Mvc.InsertionMode.insertAfter"); Assert.AreEqual(AjaxExtensions.InsertionModeToString(InsertionMode.InsertBefore), "Sys.Mvc.InsertionMode.insertBefore"); Assert.AreEqual(AjaxExtensions.InsertionModeToString((InsertionMode)4), "4"); }
public void JavaScriptStringEncodeReturnsEmptyStringIfMessageIsEmpty() { // Act string encoded = AjaxExtensions.JavaScriptStringEncode(null /* helper */, String.Empty); // Assert Assert.AreEqual(String.Empty, encoded); }
public void JavaScriptStringEncodeReturnsNullIfMessageIsNull() { // Act string encoded = AjaxExtensions.JavaScriptStringEncode(null /* helper */, null /* message */); // Assert Assert.IsNull(encoded); }
public IActionResult Register(string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (AjaxExtensions.IsAjaxRequest(Request)) { return(PartialView()); } return(View()); }
// Summary: // Represents support for ASP.NET AJAX within an ASP.NET MVC application. #region ActionLink // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // ajaxOptions: // An object that provides options for the asynchronous request. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, AjaxOptions ajaxOptions); // // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // routeValues: // An object that contains the parameters for a route. The parameters are retrieved // through reflection by examining the properties of the object. This object // is typically created by using object initializer syntax. // // ajaxOptions: // An object that provides options for the asynchronous request. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, object routeValues, AjaxOptions ajaxOptions); // // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // routeValues: // An object that contains the parameters for a route. // // ajaxOptions: // An object that provides options for the asynchronous request. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, RouteValueDictionary routeValues, AjaxOptions ajaxOptions); // // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // controllerName: // The name of the controller. // // ajaxOptions: // An object that provides options for the asynchronous request. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, AjaxOptions ajaxOptions); // // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // routeValues: // An object that contains the parameters for a route. The parameters are retrieved // through reflection by examining the properties of the object. This object // is typically created by using object initializer syntax. // // ajaxOptions: // An object that provides options for the asynchronous request. // // htmlAttributes: // An object that contains the HTML attributes to set for the element. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes); // // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // routeValues: // An object that contains the parameters for a route. // // ajaxOptions: // An object that provides options for the asynchronous request. // // htmlAttributes: // An object that contains the HTML attributes to set for the element. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, RouteValueDictionary routeValues, AjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes); // // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // controllerName: // The name of the controller. // // routeValues: // An object that contains the parameters for a route. The parameters are retrieved // through reflection by examining the properties of the object. This object // is typically created by using object initializer syntax. // // ajaxOptions: // An object that provides options for the asynchronous request. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, object routeValues, AjaxOptions ajaxOptions); // // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // controllerName: // The name of the controller. // // routeValues: // An object that contains the parameters for a route. // // ajaxOptions: // An object that provides options for the asynchronous request. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, AjaxOptions ajaxOptions); // // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // controllerName: // The name of the controller. // // routeValues: // An object that contains the parameters for a route. The parameters are retrieved // through reflection by examining the properties of the object. This object // is typically created by using object initializer syntax. // // ajaxOptions: // An object that provides options for the asynchronous request. // // htmlAttributes: // An object that contains the HTML attributes to set for the element. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes); // // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // controllerName: // The name of the controller. // // routeValues: // An object that contains the parameters for a route. // // ajaxOptions: // An object that provides options for the asynchronous request. // // htmlAttributes: // An object that contains the HTML attributes to set for the element. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, AjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes); // // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // controllerName: // The name of the controller. // // protocol: // The protocol for the URL, such as "http" or "https". // // hostName: // The host name for the URL. // // fragment: // The URL fragment name (the anchor name). // // routeValues: // An object that contains the parameters for a route. The parameters are retrieved // through reflection by examining the properties of the object. This object // is typically created by using object initializer syntax. // // ajaxOptions: // An object that provides options for the asynchronous request. // // htmlAttributes: // An object that contains the HTML attributes to set for the element. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes); // // Summary: // Returns an anchor element that contains the URL to the specified action method; // when the action link is clicked, the action method is invoked asynchronously // by using JavaScript. // // Parameters: // ajaxHelper: // The AJAX helper. // // linkText: // The inner text of the anchor element. // // actionName: // The name of the action method. // // controllerName: // The name of the controller. // // protocol: // The protocol for the URL, such as "http" or "https". // // hostName: // The host name for the URL. // // fragment: // The URL fragment name (the anchor name). // // routeValues: // An object that contains the parameters for a route. // // ajaxOptions: // An object that provides options for the asynchronous request. // // htmlAttributes: // An object that contains the HTML attributes to set for the element. // // Returns: // An anchor element. // // Exceptions: // System.ArgumentException: // The linkText parameter is null or empty. //public static MvcHtmlString ActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, AjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes); public static MvcHtmlString ActionLinkImage(this AjaxHelper ajaxHelper, string urlImage, string linkText, string actionName, object routeValues, AjaxOptions ajaxOptions) { String mvc = AjaxExtensions.ActionLink(ajaxHelper, linkText, actionName, ajaxOptions).ToHtmlString(); StringBuilder sb = new StringBuilder("", HelperBaseExtensions.Capacity); sb.Append(mvc.Substring(0, mvc.LastIndexOf(linkText))); sb.Append(String.Format("<img src='{0}'/>", urlImage)); sb.Append("</a>"); return(MvcHtmlString.Create(sb.ToString())); }
public void JavaScriptStringEncodeReturnsEncodedMessage() { // Arrange string message = "I said, \"Hello, world!\"\nHow are you?"; // Act string encoded = AjaxExtensions.JavaScriptStringEncode(null /* helper */, message); // Assert Assert.AreEqual(@"I said, \""Hello, world!\""\nHow are you?", encoded); }
public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; var isAjax = AjaxExtensions.IsAjaxRequest(Request); if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { _logger.LogInformation(1, "User logged in."); return(RedirectToLocal(returnUrl)); } if (result.RequiresTwoFactor) { return(RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning(2, "User account locked out."); if (isAjax) { return(PartialView("Lockout")); } return(View("Lockout")); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); if (isAjax) { return(PartialView(model)); } return(View(model)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public MvcHtmlString InitPagerAjax(AjaxHelper ajaxHelper) { int num = this.TotalRecords / this.PageSize; if (this.TotalRecords % this.PageSize > 0) { num++; } RouteValueDictionary routeValueDictionary = new RouteValueDictionary(this.RouteValues); routeValueDictionary.Add("controller", this.ControllerName); routeValueDictionary.Add("action", this.ActionName); string text = this.FirstText; string text2 = this.PreviousText; string text3 = this.NextText; string text4 = this.LastText; routeValueDictionary.Add("page", 1); text = ((this.PageIndex == 1) ? (this.FirstText + " ") : (AjaxExtensions.RouteLink(ajaxHelper, this.FirstText, routeValueDictionary, this.AjaxOption).ToHtmlString() + " ")); routeValueDictionary["page"] = num; text4 = ((this.PageIndex == num) ? (this.LastText + " ") : (AjaxExtensions.RouteLink(ajaxHelper, this.LastText, routeValueDictionary, this.AjaxOption).ToHtmlString() + " ")); routeValueDictionary["page"] = this.PageIndex + 1; text3 = ((this.PageIndex == num) ? (this.NextText + " ") : (AjaxExtensions.RouteLink(ajaxHelper, this.NextText, routeValueDictionary, this.AjaxOption).ToHtmlString() + " ")); routeValueDictionary["page"] = this.PageIndex - 1; text2 = ((this.PageIndex == 1) ? (this.PreviousText + " ") : (AjaxExtensions.RouteLink(ajaxHelper, this.PreviousText, routeValueDictionary, this.AjaxOption).ToHtmlString() + " ")); string text5 = ""; if (num <= this.PageRange) { text5 = ""; for (int i = 1; i <= num; i++) { if (this.PageIndex == i) { text5 += i.ToString(); } else { routeValueDictionary["page"] = i; text5 += AjaxExtensions.RouteLink(ajaxHelper, i.ToString(), routeValueDictionary, this.AjaxOption).ToHtmlString(); } text5 += " "; } } else { for (int i = 0; i <= num / this.PageRange; i++) { int num2 = this.PageRange * i; int num3 = (this.PageRange * (i + 1) > num) ? num : (this.PageRange * (i + 1)); if (this.PageIndex > num2 && this.PageIndex <= num3) { text5 = ""; if (num2 > 0) { routeValueDictionary["page"] = num2; text5 += AjaxExtensions.RouteLink(ajaxHelper, this.PreviousRangeText, routeValueDictionary, this.AjaxOption).ToHtmlString(); text5 += " "; } for (int j = num2 + 1; j <= num3; j++) { if (this.PageIndex == j) { text5 += j.ToString(); } else { routeValueDictionary["page"] = j; text5 += AjaxExtensions.RouteLink(ajaxHelper, j.ToString(), routeValueDictionary, this.AjaxOption).ToHtmlString(); } text5 += " "; } if (num3 < num) { routeValueDictionary["page"] = num3 + 1; text5 += AjaxExtensions.RouteLink(ajaxHelper, this.NextRangeText, routeValueDictionary, this.AjaxOption).ToHtmlString(); text5 += " "; } } } } string text6 = this.ShowNote ? string.Format("{0}:{1} {2} - {3}/{4} {5}: ", new object[] { this.TotalText, this.TotalRecords, this.TotalRecordsText, this.PageIndex, num, this.PageText }) : ""; return(MvcHtmlString.Create(string.Concat(new string[] { text6, text, text2, text5, text3, text4 }))); }
/// <summary> /// 返回一个非注入式Ajax链接 /// </summary> /// <param name="ajaxHelper"></param> /// <param name="linkText">链接文字</param> /// <param name="actionName">动作名</param> /// <param name="controllerName">控制器名</param> /// <param name="areaName">区域名</param> /// <param name="htmlAttributes">html特性</param> /// <param name="ajaxOptions">Ajax参数</param> public static MvcHtmlString AsiatekActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, string areaName, object htmlAttributes, AjaxOptions ajaxOptions) { return(AjaxExtensions.ActionLink(ajaxHelper, linkText, actionName, controllerName, new { area = areaName }, ajaxOptions, htmlAttributes)); }
public static MvcHtmlString Sayfalama(this AjaxHelper helper, int SayfaNo, int ToplamKayit, string ActionName, int SayfaGosterim = 3, string HedefDiv = "icerik") { if (ToplamKayit >= SayfaGosterim) { AjaxOptions ao = new AjaxOptions(); ao.UpdateTargetId = HedefDiv; ao.LoadingElementId = "progress"; StringBuilder sb = new StringBuilder(); int ToplamSayfaSayisi = 0; object ilkYaz = ""; object geriYaz = ""; object ileriYaz = ""; object sonYaz = ""; if (ToplamKayit % SayfaGosterim == 0) { ToplamSayfaSayisi = ToplamKayit / SayfaGosterim; } else { ToplamSayfaSayisi = ToplamKayit / SayfaGosterim + 1; } #region Sayfa 10 Adet Gösterme int ilkGosterim = SayfaNo; int sonGosterim = SayfaNo; if (ToplamSayfaSayisi - 1 == SayfaNo) { ilkGosterim = ilkGosterim - 9; } else if (ToplamSayfaSayisi - 2 == SayfaNo) { ilkGosterim = ilkGosterim - 8; } else if (ToplamSayfaSayisi - 3 == SayfaNo) { ilkGosterim = ilkGosterim - 7; } else if (ToplamSayfaSayisi - 4 == SayfaNo) { ilkGosterim = ilkGosterim - 6; } else { ilkGosterim = ilkGosterim - 5; } switch (sonGosterim) { case 0: sonGosterim = 10; break; case 1: sonGosterim = 10; break; case 2: sonGosterim = 10; break; case 3: sonGosterim = 10; break; case 4: sonGosterim = 10; break; default: sonGosterim = sonGosterim + 5; break; } #endregion #region İlk Sayfa ve En son Sayfa İşlemi if (!(ToplamSayfaSayisi <= 10)) { if (SayfaNo == ToplamSayfaSayisi - 1) { sonYaz = "<span class='Last Page' > Son Sayfa </span>\n"; } else { sonYaz = AjaxExtensions.ActionLink(helper, "Son Sayfa", ActionName, new { Sayfa = ToplamSayfaSayisi - 1 }, ao, new { @class = "Last Page" }); } if (SayfaNo == 0) { ilkYaz = "<span class='First Page' > İlk Sayfa </span>\n"; } else { ilkYaz = AjaxExtensions.ActionLink(helper, "İlk Sayfa", ActionName, new { Sayfa = 0 }, ao, new { @class = "First Page" }); } } #endregion for (int i = 0; i < ToplamSayfaSayisi; i++) { if (i >= ilkGosterim && i < sonGosterim) { if (i == SayfaNo) { sb.Append("<a class='current' >" + (i + 1) + "</a>\n"); } else { sb.Append(AjaxExtensions.ActionLink(helper, Convert.ToString((i + 1)), ActionName, new { Sayfa = (i) }, ao, new { @class = "number" })); } } } #region Sayfa İleri Geri İşlemi SayfaNo = SayfaNo + 1; int geri = SayfaNo - 2; if (geri < 0) { geriYaz = "<span class='Previous Page' > « Geri </span>\n"; } else { geriYaz = AjaxExtensions.ActionLink(helper, "« Geri", ActionName, new { Sayfa = geri }, ao, new { @class = "Previous Page" }); } if (SayfaNo >= ToplamSayfaSayisi) { ileriYaz = "<span class='Next Page' > İleri » </span>\n"; } else { ileriYaz = AjaxExtensions.ActionLink(helper, "İleri »", ActionName, new { Sayfa = SayfaNo }, ao, new { @class = "Next Page" }); } #endregion string toplamMetin = "<div class='pageTotal' > Toplam: " + ToplamKayit.ToString() + "</div>"; return(MvcHtmlString.Create(ilkYaz.ToString() + geriYaz.ToString() + sb.ToString() + ileriYaz.ToString() + sonYaz.ToString() + toplamMetin)); } else { return(MvcHtmlString.Create("")); } }