本文整理汇总了C#中System.Web.Mvc.AjaxHelper.ActionLink方法的典型用法代码示例。如果您正苦于以下问题:C# AjaxHelper.ActionLink方法的具体用法?C# AjaxHelper.ActionLink怎么用?C# AjaxHelper.ActionLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.AjaxHelper
的用法示例。
在下文中一共展示了AjaxHelper.ActionLink方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteLink
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(); }"
});
}
示例2: ComposeImageActionLink
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)));
}
示例3: GenerateFullCaptcha
/// <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"));
}
示例4: CustomActionLink
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).;
}
示例5: GenerateFullCaptcha
/// <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)));
}
示例6: CreateActionLink
/// <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>";
}