本文整理汇总了C#中System.Web.Mvc.UrlHelper.RedirectToProvider方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.RedirectToProvider方法的具体用法?C# UrlHelper.RedirectToProvider怎么用?C# UrlHelper.RedirectToProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.RedirectToProvider方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RedirectToProvider
//public static IHtmlString RedirectToProvider(this HtmlHelper htmlHelper,
// string providerName,
// string imagePath,
// string imageAlternativeText)
//{
// return RedirectToProvider(htmlHelper, providerName, imagePath, imageAlternativeText, null, null, null);
//}
//public static IHtmlString RedirectToProvider(this HtmlHelper htmlHelper,
// string providerName,
// string imagePath,
// string imageAlternativeText = null,
// string returnUrl = null,
// IDictionary<string, object> imageHtmltmlAttributes = null,
// IDictionary<string, object> htmlAttributes = null
// )
//{
// if (string.IsNullOrEmpty(providerName))
// {
// throw new ArgumentNullException("providerName",
// "Missing a providerName value. Please provide one so we know what route to generate.");
// }
// if (string.IsNullOrEmpty(imagePath))
// {
// throw new ArgumentNullException("imagePath",
// "Missing an imagePath value. Please provide one so we know which image to display. Eg. \"Content/google.png\"");
// }
// // Lets generate a link.
// var tagBuilder = new TagBuilder("img");
// // Image src="xxxx" attribute.
// var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
// var url = urlHelper.Content(imagePath);
// tagBuilder.MergeAttribute("src", url);
// // 'Alt' attribute.
// if (!string.IsNullOrEmpty(imageAlternativeText))
// {
// tagBuilder.MergeAttribute("alt", imageAlternativeText);
// }
// // Merge any optional attributes. For example, class values, etc.
// if (htmlAttributes != null)
// {
// tagBuilder.MergeAttributes(imageHtmltmlAttributes);
// }
// string imageHtml = tagBuilder.ToString(TagRenderMode.SelfClosing);
// return RedirectToProvider(htmlHelper, providerName, imageHtml, returnUrl, htmlAttributes);
//}
public static IHtmlString RedirectToProvider(this HtmlHelper htmlHelper,
string providerName,
string innerHtml,
string returnUrl = null,
IDictionary<string, object> htmlAttributes = null)
{
if (string.IsNullOrEmpty(providerName))
{
throw new ArgumentNullException("providerName",
"Missing a providerName value. Please provide one so we know what route to generate.");
}
if (string.IsNullOrEmpty(innerHtml))
{
throw new ArgumentNullException("innerHtml",
"Missing an innerHtml value. We need to display some link text or image to be able to click on - so please provide some html. eg. <img src=\"/ContentResult/someButton.png\" alt=\"click me\"/>");
}
// Start with an <a /> element.
var tagBuilder = new TagBuilder("a")
{
InnerHtml = innerHtml
};
// Merge any optional attributes. For example, class values, etc.
if (htmlAttributes != null)
{
tagBuilder.MergeAttributes(htmlAttributes);
}
// Determine the route.
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
var url = urlHelper.RedirectToProvider(providerName, returnUrl);
// Set the route.
tagBuilder.MergeAttribute("href", url);
return new HtmlString(tagBuilder.ToString(TagRenderMode.Normal));
}