本文整理汇总了C#中System.Web.Mvc.UrlHelper.Action方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.Action方法的具体用法?C# UrlHelper.Action怎么用?C# UrlHelper.Action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.Action方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MvcCaptcha
private static MvcHtmlString MvcCaptcha(this HtmlHelper helper, string actionName, string controllerName, MvcCaptchaOptions options)
{
if (options == null)
{
options = new MvcCaptchaOptions();
}
MvcCaptchaImage mvcCaptchaImage = new MvcCaptchaImage(options);
HttpContext.Current.Session.Add(mvcCaptchaImage.UniqueId, mvcCaptchaImage);
UrlHelper urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
StringBuilder stringBuilder = new StringBuilder(1500);
stringBuilder.Append("\r\n<!--MvcCaptcha 1.1 for ASP.NET MVC 2 RC Copyright:2009-2010 Webdiyer (http://www.webdiyer.com)-->\r\n");
stringBuilder.Append("<input type=\"hidden\" name=\"_mvcCaptchaGuid\" id=\"_mvcCaptchaGuid\"");
if (options.DelayLoad)
{
stringBuilder.Append("/><script language=\"javascript\" type=\"text/javascript\">if (typeof (jQuery) == \"undefined\") { alert(\"jQuery脚本库未加载,请检查!\"); }");
stringBuilder.Append("var _mvcCaptchaPrevGuid = null,_mvcCaptchaImgLoaded = false;function _loadMvcCaptchaImage(){");
stringBuilder.Append("if(!_mvcCaptchaImgLoaded){$.ajax({type:'GET',url:'");
stringBuilder.Append(urlHelper.Action("MvcCaptchaLoader", "_MvcCaptcha", new RouteValueDictionary
{
{
"area",
null
}
}));
stringBuilder.Append("?'+_mvcCaptchaPrevGuid,global:false,success:function(data){_mvcCaptchaImgLoaded=true;");
stringBuilder.Append("$(\"#_mvcCaptchaGuid\").val(data);_mvcCaptchaPrevGuid=data;$(\"#");
stringBuilder.Append(options.CaptchaImageContainerId).Append("\").html('");
stringBuilder.Append(MvcCaptchaHelper.CreateImgTag(urlHelper.Action(actionName, controllerName, new RouteValueDictionary
{
{
"area",
null
}
}) + "?'+data+'", options, null));
stringBuilder.Append("');}});} };function _reloadMvcCaptchaImage(){_mvcCaptchaImgLoaded=false;_loadMvcCaptchaImage();};$(function(){");
stringBuilder.Append("if($(\"#").Append(options.ValidationInputBoxId).Append("\").length==0){alert(\"未能找到验证码输入文本框,请检查ValidationInputBoxId属性是否设置正确!\");}");
stringBuilder.Append("if($(\"#").Append(options.CaptchaImageContainerId).Append("\").length==0){alert(\"未能找到验证码图片父容器,请检查CaptchaImageContainerId属性是否设置正确!\");}");
stringBuilder.Append("$(\"#").Append(options.ValidationInputBoxId);
stringBuilder.Append("\").bind(\"focus\",_loadMvcCaptchaImage)});</script>");
}
else
{
stringBuilder.AppendFormat(" value=\"{0}\" />", mvcCaptchaImage.UniqueId);
stringBuilder.Append(MvcCaptchaHelper.CreateImgTag(urlHelper.Action(actionName, controllerName, new RouteValueDictionary
{
{
"area",
null
}
}) + "?" + mvcCaptchaImage.UniqueId, options, mvcCaptchaImage.UniqueId));
stringBuilder.Append("<script language=\"javascript\" type=\"text/javascript\">function _reloadMvcCaptchaImage(){var ci=document.getElementById(\"");
stringBuilder.Append(mvcCaptchaImage.UniqueId);
stringBuilder.Append("\");var sl=ci.src.length;if(ci.src.indexOf(\"&\")>-1)sl=ci.src.indexOf(\"&\");ci.src=ci.src.substr(0,sl)+\"&\"+(new Date().valueOf());}</script>");
}
stringBuilder.Append("\r\n<!--MvcCaptcha 1.1 for ASP.NET MVC 2 RC Copyright:2009-2010 Webdiyer (http://www.webdiyer.com)-->\r\n");
return MvcHtmlString.Create(stringBuilder.ToString());
}
示例2: ActionImageLink
public static MvcHtmlString ActionImageLink(this HtmlHelper helper, string src, string altText, UrlHelper url, string actionName, string controllerName, dynamic routeValues, Dictionary<string, string> linkAttributes, Dictionary<string, string> imageAttributes)
{
var linkBuilder = new TagBuilder("a");
linkBuilder.MergeAttribute("href", routeValues == null ? url.Action(actionName, controllerName) : url.Action(actionName, controllerName, routeValues));
var imageBuilder = new TagBuilder("img");
imageBuilder.MergeAttribute("src", url.Content(src));
imageBuilder.MergeAttribute("alt", altText);
if (linkAttributes != null)
{
foreach (KeyValuePair<string, string> attribute in linkAttributes)
{
if (!string.IsNullOrWhiteSpace(attribute.Key) && !string.IsNullOrWhiteSpace(attribute.Value))
{
linkBuilder.MergeAttribute(attribute.Key, attribute.Value);
}
}
}
if (imageAttributes != null)
{
foreach (KeyValuePair<string, string> attribute in imageAttributes)
{
if (!string.IsNullOrWhiteSpace(attribute.Key) && !string.IsNullOrWhiteSpace(attribute.Value))
{
imageBuilder.MergeAttribute(attribute.Key, attribute.Value);
}
}
}
linkBuilder.InnerHtml = MvcHtmlString.Create(imageBuilder.ToString(TagRenderMode.SelfClosing)).ToString();
return MvcHtmlString.Create(linkBuilder.ToString());
}
示例3: EmployeeImageRight
public static MvcHtmlString EmployeeImageRight(this HtmlHelper helper, Employee item)
{
var url = new UrlHelper(helper.ViewContext.RequestContext);
var path = HttpContext.Current.Server.MapPath("~/public/userfiles/employees/" + item.Id + ".jpg");
if (File.Exists(path))
{
return MvcHtmlString.Create(
string.Format("<a href='{3}' class='employee-photo top-photo'><img title='{1}' src='{2}' /></a>",
url.Content("~/public/images/pix.gif"),
item.FullName,
url.Content("~/public/userfiles/employees/" + item.Id + ".jpg"),
url.Action("Card", "Employees", new { item.Id })
)
);
}
else
{
return MvcHtmlString.Create(
string.Format("<a href='{3}' class='employee-photo'><img title='{1}' style='background-size: 100%;background-image: url({2})' src='{0}' /></a>",
url.Content("~/public/images/pix.gif"),
item.FullName,
url.Content("~/public/images/picture_bg.jpg"),
url.Action("Card", "Employees", new { item.Id })
)
);
}
}
示例4: OnActionExecuting
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
if (!_fbClientProvider.IsAuthenticatedWithFb())
{
if (filterContext.ActionParameters.ContainsKey("request_ids"))
{
var urlHelper = new UrlHelper(filterContext.RequestContext);
string redirectUrl = urlHelper.Action(
actionName: filterContext.ActionDescriptor.ActionName,
controllerName: filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
routeValues: new RouteValueDictionary(filterContext.ActionParameters));
string url = urlHelper.Action(
actionName: "FacebookLogin",
controllerName: "Facebook",
routeValues:
new { state = HttpServerUtility.UrlTokenEncode(Encoding.UTF8.GetBytes(redirectUrl)) });
filterContext.Result = new RedirectResult(url);
}
}
}
示例5: CreateUrl
public static string CreateUrl(User user, UrlHelper urlHelper, HttpRequestBase request)
{
if (!user.IsPublicViewer)
return urlHelper.Action(MVC.Account.Register(user.InvitationCode), request.Url.Scheme);
else
return urlHelper.Action(MVC.Account.PublicViewerLogOn(user.InvitationCode), request.Url.Scheme);
}
示例6: InitializeSidebar
public override void InitializeSidebar(Sidebar sidebar, UrlHelper urlHelper)
{
sidebar.AddSidebarItem(SidebarObjectType.ViewDisplay, "Search", urlHelper.Action("Search", "Pages", new { area = "Admin" }));
sidebar.AddSidebarItem(SidebarObjectType.ViewDisplay, "Details", urlHelper.Action("Details", "Pages", new { area = "Admin", ActionId = ActiveSystemPage.ActionId }));
base.InitializeSidebar(sidebar, urlHelper);
}
示例7: JsonExternalLogin
public JsonResult JsonExternalLogin(LoginModel model, string ReturnUrl)
{
if (ModelState.IsValid)
{
//Step 1: Get data from Sp and check it
AccountBL Ab = new AccountBL();
ContactDetails cd = new ContactDetails();
cd = Ab.CheckLogin(model.UserName, model.Password);
if (cd.CustomerID > 0)
{
//cd.CustomerID = 0;
FormsAuthentication.SetAuthCookie(model.UserName, false);
SiteSession siteSession = new SiteSession(cd);
SessionHelper.UserSession = siteSession;
UrlHelper u = new UrlHelper(HttpContext.Request.RequestContext);
string url = string.Empty;
if (SessionHelper.UserSession.RoleID == UserRole.SuperAdmin ||
SessionHelper.UserSession.RoleID == UserRole.Admin||
SessionHelper.UserSession.RoleID == UserRole.Staff)
url = u.Action("Index", "Search", null);
else
url = u.Action("Index", "SetupCustomer", null);
return Json(new { success = true, redirect = string.IsNullOrEmpty(ReturnUrl) ? url : ReturnUrl });
}
else
{
ModelState.AddModelError("", "Please provide valid User Name/Password.");
}
}
return Json(new { errors = KeyValue.GetErrorsFromModelState(ViewData) });
}
示例8: OnActionExecuting
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!LoginCenter.IsUserLogin() || LoginCenter.CurrentUser.Role == Role.Company) return;
var onLine = HttpContext.Current.Application[LotterySystem.M_ONLINEUSERCOUNT] as IDictionary<int, Pair<string, Role>>;
string sessionId = HttpContext.Current.Session.SessionID;
int userId = onLine.Where(it => it.Value.Key == sessionId).Select(it => it.Key).SingleOrDefault();
if (!onLine.ContainsKey(userId))
{
LoginCenter lotinCentre = new LoginCenter();
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
filterContext.Result = new JsonResult
{
Data = new JsonResultModel
{
IsSuccess = false,
Message = Resource.LoginByOtherOne
}
};
}
else
{
var urlHelper = new UrlHelper(filterContext.RequestContext);
string actionUrl = urlHelper.Action("Error", "Prompt");
string loginUrl = urlHelper.Action(LoginCenter.CurrentUser.Role == Role.Guest ? "Login" : "Agent", "Member");
string redirectUrl = string.Format("{0}?Url={1}&Msg={2}", actionUrl, loginUrl, Resource.LoginByOtherOne);
filterContext.Result = new RedirectResult(redirectUrl);
}
lotinCentre.Logout();
}
}
示例9: BreadcrumbFromPath
public static MvcHtmlString BreadcrumbFromPath(this HtmlHelper html, string element, PaneState.PaneType type, string path, NameValueCollection requestParams, bool active = false)
{
var liTag = new TagBuilder("li");
var urlHelper = new UrlHelper(html.ViewContext.RequestContext);
string url = "";
switch (type)
{
case PaneState.PaneType.Left:
url = urlHelper.Action("Index", new { leftPath = path, rightPath = requestParams["rightPath"] });
break;
case PaneState.PaneType.Right:
url = urlHelper.Action("Index", new { leftPath = requestParams["leftPath"], rightPath = path });
break;
}
var aTag = new TagBuilder("a");
aTag.MergeAttribute("href", url);
aTag.InnerHtml = element;
liTag.InnerHtml = aTag.ToString();
if (active)
{
liTag.AddCssClass("active");
}
return MvcHtmlString.Create(liTag.ToString());
}
示例10: ActionButton
public static MvcHtmlString ActionButton(this HtmlHelper html, string linkText, string action, string controllerName, string iconClass, string value = null)
{
//<a href="/@lLink.ControllerName/@lLink.ActionName" title="@lLink.LinkText"><i class="@lLink.IconClass"></i><span class="">@lLink.LinkText</span></a>
var lURL = new UrlHelper(html.ViewContext.RequestContext);
// build the <span class="">@lLink.LinkText</span> tag
var lSpanBuilder = new TagBuilder("span");
lSpanBuilder.MergeAttribute("class", "");
lSpanBuilder.SetInnerText(linkText);
string lSpanHtml = lSpanBuilder.ToString(TagRenderMode.Normal);
// build the <i class="@lLink.IconClass"></i> tag
var lIconBuilder = new TagBuilder("i");
lIconBuilder.MergeAttribute("class", iconClass);
string lIconHtml = lIconBuilder.ToString(TagRenderMode.Normal);
// build the <a href="@lLink.ControllerName/@lLink.ActionName" title="@lLink.LinkText">...</a> tag
var lAnchorBuilder = new TagBuilder("a");
if (string.IsNullOrEmpty(value))
{
lAnchorBuilder.MergeAttribute("href", lURL.Action(action, controllerName));
}
else
{
lAnchorBuilder.MergeAttribute("href", lURL.Action(action, controllerName, new { id = value }));
}
lAnchorBuilder.InnerHtml = lIconHtml + lSpanHtml; // include the <i> and <span> tags inside
string lAnchorHtml = lAnchorBuilder.ToString(TagRenderMode.Normal);
return MvcHtmlString.Create(lAnchorHtml);
}
示例11: ActionImage
// Extension method
public static MvcHtmlString ActionImage(this HtmlHelper html, string action, string controllerName, string imagePath, string alt, string anchorCssClass, string imgCssClass, object routeAttributes)
{
var url = new UrlHelper(html.ViewContext.RequestContext);
// build the <img> tag
var imgBuilder = new TagBuilder("img");
imgBuilder.MergeAttribute("src", url.Content(imagePath));
imgBuilder.MergeAttribute("alt", alt);
if(imgCssClass != null)
imgBuilder.AddCssClass(imgCssClass);
string imgHtml = imgBuilder.ToString(TagRenderMode.SelfClosing);
// build the <a> tag
var anchorBuilder = new TagBuilder("a");
if (routeAttributes == null)
anchorBuilder.MergeAttribute("href", url.Action(action, controllerName));
else
anchorBuilder.MergeAttribute("href", url.Action(action, controllerName, routeAttributes));
anchorBuilder.InnerHtml = imgHtml; // include the <img> tag inside
if(anchorCssClass != null)
anchorBuilder.AddCssClass(anchorCssClass);
string anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal);
return MvcHtmlString.Create(anchorHtml);
}
示例12: BuildUrl
private string BuildUrl(ControllerContext filterContext)
{
UrlHelper urlHelper = new UrlHelper(filterContext.RequestContext);
string url;
if (!string.IsNullOrEmpty(RouteName))
{
url = urlHelper.RouteUrl(RouteName);
}
else if (!string.IsNullOrEmpty(ControllerName) && !string.IsNullOrEmpty(ActionName))
{
url = urlHelper.Action(ActionName, ControllerName);
}
else if (!string.IsNullOrEmpty(ActionName))
{
url = urlHelper.Action(ActionName);
}
else
{
url = filterContext.HttpContext.Request.RawUrl;
}
url += "?" + filterContext.HttpContext.Request.QueryString;
url = url.TrimEnd('?');
return url;
}
示例13: GetSitemapNodes
protected internal override IEnumerable<SitemapNode> GetSitemapNodes(UrlHelper urlHelper, HttpContextBase httpContext)
{
yield return new SitemapNode(urlHelper.Action("Index", "Home")) { Priority = 1 };
yield return new SitemapNode(urlHelper.Action("Info", "Home")) { Priority = .25m };
yield return new SitemapNode(urlHelper.Action("GettingStarted", "Home")) { Priority = 1 };
yield return new SitemapNode(urlHelper.Action("Downloads", "Home")) { Priority = .25m };
}
示例14: OnResultExecuting
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
var url = new UrlHelper(filterContext.RequestContext);
var id = filterContext.RouteData.Values["id"];
if (filterContext.Controller.GetType() == typeof(DataCollectionController))
{
var projectId = filterContext.RouteData.Values["projectId"];
filterContext.Controller.ViewBag.Steps = new List<Step>
{
new Step {Url = url.Action("Step1", "DataCollection", new {id, projectId}), Name = "Section 1"},
new Step {Url = url.Action("Step2", "DataCollection", new {id, projectId}), Name = "Section 2"}
};
filterContext.Controller.ViewBag.MaxStep = 2;
}
else if (filterContext.Controller.GetType() == typeof(ApprovalController))
{
filterContext.Controller.ViewBag.Steps = new List<Step>
{
new Step {Url = url.Action("Step1", "Approval", new {id }), Name = "Section 1"},
new Step {Url = url.Action("Step2", "Approval", new {id }), Name = "Section 2"},
new Step {Url = url.Action("Confirm", "Approval", new {id}), Name = "Confirm"}
};
filterContext.Controller.ViewBag.MaxStep = 2;
}
}
开发者ID:SharePointSusan,项目名称:Research-Data-Manager,代码行数:27,代码来源:ProvideDataCollectionStepsAttribute.cs
示例15: GetRedirectResultByExceptionType
private static ActionResult GetRedirectResultByExceptionType(string errType, ExceptionContext exceptionContext)
{
var urlHelper = new UrlHelper(exceptionContext.HttpContext.Request.RequestContext);
var exception = exceptionContext.Exception;
var iController = exceptionContext.Controller as IControllerProperties;
var isAdminController = iController != null && iController.IsAdminController;
if (exception is UnauthorizedAccessException)
errType = "unauthorized";
else if (exception is InvalidMonthException)
errType = "invalid-month";
ActionResult redirectTo = isAdminController ? new RedirectResult(urlHelper.Action("Error","Admin", new { Area = "Admin", err = errType }))
: new RedirectResult(urlHelper.Action("Error", "Home", new { Area = "", err = errType }));
if (exception is UrlNotFoundException)
redirectTo = new RedirectToRouteResult("Error404", new RouteValueDictionary());
if (exception is InvalidThemeException)
redirectTo = new RedirectToRouteResult("InvalidTheme", new RouteValueDictionary());
if (exception is SqlException)
redirectTo = new RedirectToRouteResult("InitializeDatabase", new RouteValueDictionary());
return redirectTo;
}