本文整理汇总了C#中UrlHelper类的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper类的具体用法?C# UrlHelper怎么用?C# UrlHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UrlHelper类属于命名空间,在下文中一共展示了UrlHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MenuItemCheveron
public static MvcHtmlString MenuItemCheveron(this HtmlHelper htmlHelper,
string text, string action, string controller,
string cheveronText, string area = null)
{
var li = new TagBuilder("li");
var routeData = htmlHelper.ViewContext.RouteData;
var currentAction = routeData.GetRequiredString("action");
var currentController = routeData.GetRequiredString("controller");
var currentArea = routeData.DataTokens["area"] as string;
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection);
if (string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase) &&
string.Equals(currentController, controller, StringComparison.OrdinalIgnoreCase) &&
string.Equals(currentArea, area, StringComparison.OrdinalIgnoreCase))
{
li.AddCssClass("active");
}
var linkBuilder = new TagBuilder("a");
linkBuilder.MergeAttribute("href", urlHelper.Action(action, controller));
var htmlText = li.ToString(TagRenderMode.StartTag);
htmlText += linkBuilder.ToString(TagRenderMode.StartTag);
htmlText += text;
htmlText += linkBuilder.ToString(TagRenderMode.EndTag);
htmlText += li.ToString(TagRenderMode.EndTag);
return MvcHtmlString.Create(htmlText.ToString());
}
开发者ID:sg0193,项目名称:Waterforafrica,代码行数:28,代码来源:HtmlExtensions.cs
示例2: ImageLink
public static MvcHtmlString ImageLink(this HtmlHelper html, string action, string controller, object routeValues, string imageURL, string hoverImageURL, string alternateText, object linkHtmlAttributes, object imageHtmlAttributes)
{
// Create an instance of UrlHelper
UrlHelper url = new UrlHelper(html.ViewContext.RequestContext);
// Create image tag builder
TagBuilder imageBuilder = new TagBuilder("img");
// Add image attributes
imageBuilder.MergeAttribute("src", imageURL);
imageBuilder.MergeAttribute("alt", alternateText);
imageBuilder.MergeAttribute("title", alternateText);
//support for hover
imageBuilder.MergeAttribute("onmouseover", "this.src='" + hoverImageURL + "'");
imageBuilder.MergeAttribute("onmouseout", "this.src='" + imageURL + "'");
imageBuilder.MergeAttribute("border", "0");
imageBuilder.MergeAttributes(new RouteValueDictionary(imageHtmlAttributes));
// Create link tag builder
TagBuilder linkBuilder = new TagBuilder("a");
// Add attributes
linkBuilder.MergeAttribute("href", url.Action(action, controller, new RouteValueDictionary(routeValues)));
linkBuilder.InnerHtml = imageBuilder.ToString(TagRenderMode.SelfClosing);
linkBuilder.MergeAttributes(new RouteValueDictionary(linkHtmlAttributes));
// Render tag
return MvcHtmlString.Create(linkBuilder.ToString(TagRenderMode.Normal));
}
开发者ID:lgulliver,项目名称:ImageLinkHelper,代码行数:26,代码来源:ImageLinkHelper.cs
示例3: ActionImage
public static MvcHtmlString ActionImage(this HtmlHelper html, string action, string controllerName, object routeValues, string imagePath, string alt, string confirmMessage, bool newWindow)
{
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);
string imgHtml = imgBuilder.ToString(TagRenderMode.SelfClosing);
// build the <a> tag
var anchorBuilder = new TagBuilder("a");
anchorBuilder.MergeAttribute("href", url.Action(action, controllerName, routeValues));
anchorBuilder.InnerHtml = imgHtml; // include the <img> tag inside
if (!string.IsNullOrEmpty(confirmMessage))
anchorBuilder.MergeAttribute("onclick", "return confirm('" + confirmMessage + "')");
if (newWindow)
anchorBuilder.MergeAttribute("target", "_blank");
string anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal);
return MvcHtmlString.Create(anchorHtml);
}
开发者ID:anlugifa,项目名称:BootWrapper,代码行数:25,代码来源:MvcHtmlExtentions.cs
示例4: BuildNextLink
private static string BuildNextLink(
UrlHelper urlHelper, QueryOptions queryOptions, string actionName)
{
if (queryOptions.CurrentPage != queryOptions.TotalPages)
{
return string.Format(
"<a href=\"{0}\">Next <span aria-hidden=\"true\">→</span></a>",
urlHelper.Action(actionName, new
{
SortOrder = queryOptions.SortOrder,
SortField = queryOptions.SortField,
CurrentPage = queryOptions.CurrentPage + 1,
PageSize = queryOptions.PageSize
}));
}
else
{
return string.Format(
"<a href=\"{0}\" class=\"disabled\">Next <span aria-hidden=\"true\">→</span></a>",
urlHelper.Action(actionName, new
{
SortOrder = queryOptions.SortOrder,
SortField = queryOptions.SortField,
CurrentPage = queryOptions.CurrentPage + 1,
PageSize = queryOptions.PageSize
}));
}
}
开发者ID:loukajaj,项目名称:CSharpHomeLibrary,代码行数:28,代码来源:HtmlHelperExtension.cs
示例5: SetUp
public void SetUp()
{
string siteRoot = GetSiteRoot();
string viewPath = Path.Combine(siteRoot, "RenderingTests\\Views");
Layout = null;
PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
Helpers = new HelperDictionary();
StubMonoRailServices services = new StubMonoRailServices();
services.UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), new StubRoutingEngine());
services.UrlTokenizer = new DefaultUrlTokenizer();
UrlInfo urlInfo = new UrlInfo(
"example.org", "test", "/TestBrail", "http", 80,
"http://test.example.org/test_area/test_controller/test_action.tdd",
Area, ControllerName, Action, "tdd", "no.idea");
StubEngineContext = new StubEngineContext(new StubRequest(), new StubResponse(), services,
urlInfo);
StubEngineContext.AddService<IUrlBuilder>(services.UrlBuilder);
StubEngineContext.AddService<IUrlTokenizer>(services.UrlTokenizer);
StubEngineContext.AddService<IViewComponentFactory>(ViewComponentFactory);
StubEngineContext.AddService<ILoggerFactory>(new ConsoleFactory());
StubEngineContext.AddService<IViewSourceLoader>(new FileAssemblyViewSourceLoader(viewPath));
ViewComponentFactory = new DefaultViewComponentFactory();
ViewComponentFactory.Service(StubEngineContext);
ViewComponentFactory.Initialize();
ControllerContext = new ControllerContext();
ControllerContext.Helpers = Helpers;
ControllerContext.PropertyBag = PropertyBag;
StubEngineContext.CurrentControllerContext = ControllerContext;
Helpers["urlhelper"] = Helpers["url"] = new UrlHelper(StubEngineContext);
Helpers["htmlhelper"] = Helpers["html"] = new HtmlHelper(StubEngineContext);
Helpers["dicthelper"] = Helpers["dict"] = new DictHelper(StubEngineContext);
Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(StubEngineContext);
//FileAssemblyViewSourceLoader loader = new FileAssemblyViewSourceLoader(viewPath);
// loader.AddAssemblySource(
// new AssemblySourceInfo(Assembly.GetExecutingAssembly().FullName,
// "Castle.MonoRail.Views.Brail.Tests.ResourcedViews"));
viewEngine = new AspViewEngine();
viewEngine.Service(StubEngineContext);
AspViewEngineOptions options = new AspViewEngineOptions();
options.CompilerOptions.AutoRecompilation = true;
options.CompilerOptions.KeepTemporarySourceFiles = false;
ICompilationContext context =
new CompilationContext(
new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory),
new DirectoryInfo(siteRoot),
new DirectoryInfo(Path.Combine(siteRoot, "RenderingTests\\Views")),
new DirectoryInfo(siteRoot));
List<ICompilationContext> compilationContexts = new List<ICompilationContext>();
compilationContexts.Add(context);
viewEngine.Initialize(compilationContexts, options);
}
开发者ID:ralescano,项目名称:castle,代码行数:60,代码来源:IntegrationViewTestFixture.cs
示例6: Breadcrumb
public Breadcrumb()
{
this.IsVisible = false;
UrlHelper urlHelper = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);
this.BreadcrumbPaths = new List<KeyValuePair<string, string>>();
this.BreadcrumbPaths.Add(new KeyValuePair<string, string>(GeneralTexts.Home, HomeUrlHelper.Home_Index(urlHelper)));
}
开发者ID:jordivila,项目名称:Net_MVC_NLayer_Generator,代码行数:8,代码来源:BreadcrumbModel.cs
示例7: Favicon
public static MvcHtmlString Favicon(this HtmlHelper helper)
{
UrlHelper uh = new UrlHelper(helper.ViewContext.RequestContext);
string faviconUrl = uh.Content("~/Images/favicon.ico");
return new MvcHtmlString(string.Format("<link href=\"{0}\" rel=\"shortcut icon\" type=\"image/x-icon\" />", faviconUrl));
}
开发者ID:prabhakara,项目名称:Dexter-Blog-Engine,代码行数:8,代码来源:HtmlHelperHelper.cs
示例8: SitemapPingerService
/// <summary>
/// Initializes a new instance of the <see cref="SitemapPingerService"/> class.
/// </summary>
/// <param name="loggingService">The logging service.</param>
/// <param name="urlHelper">The URL helper.</param>
public SitemapPingerService(
ILoggingService loggingService,
UrlHelper urlHelper)
{
this.loggingService = loggingService;
this.urlHelper = urlHelper;
this.httpClient = new HttpClient();
}
开发者ID:MarcusPozzan,项目名称:ASP.NET-MVC-Boilerplate,代码行数:13,代码来源:SitemapPingerService.cs
示例9: RequestContextProperty
public void RequestContextProperty() {
// Arrange
RequestContext requestContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());
UrlHelper urlHelper = new UrlHelper(requestContext);
// Assert
Assert.AreEqual(requestContext, urlHelper.RequestContext);
}
开发者ID:sanyaade-mobiledev,项目名称:ASP.NET-Mvc-2,代码行数:8,代码来源:UrlHelperTest.cs
示例10: SitemapService
/// <summary>
/// Initializes a new instance of the <see cref="SitemapService" /> class.
/// </summary>
/// <param name="cacheService">The cache service.</param>
/// <param name="loggingService">The logging service.</param>
/// <param name="urlHelper">The URL helper.</param>
public SitemapService(
ICacheService cacheService,
ILoggingService loggingService,
UrlHelper urlHelper)
{
this.cacheService = cacheService;
this.loggingService = loggingService;
this.urlHelper = urlHelper;
}
开发者ID:vivekdhami,项目名称:ASP.NET-MVC-Boilerplate,代码行数:15,代码来源:SitemapService.cs
示例11: Setup
public void Setup()
{
var controllerContext = new ControllerContext();
var engineContext = new StubEngineContext { CurrentControllerContext = controllerContext, UrlInfo = new UrlInfo("", "home", "index", "", "") };
helper = new UrlHelper(engineContext) { UrlBuilder = new DefaultUrlBuilder() };
helper.UrlBuilder.UseExtensions = false;
controllerContext.Helpers.Add(helper);
}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:9,代码来源:UrlHelperTestCase.cs
示例12: SetUp
public void SetUp()
{
_serviceProxy = new Mock<ServiceProxy>();
var type = typeof (ServiceProxy);
type.SetFieldValue("_instance", _serviceProxy.Object);
_urlHelper = new UrlHelper();
}
开发者ID:kiran-singh,项目名称:ReflectingForTesting,代码行数:9,代码来源:UrlHelperFixture.cs
示例13: HandleUnauthorizedRequest
protected void HandleUnauthorizedRequest(ref AuthorizationContext filterContext)
{
UrlHelper urlHelper = null;
if (filterContext.Controller is Controller)
{
urlHelper = ((Controller)filterContext.Controller).Url;
}
else
{
urlHelper = new UrlHelper(filterContext.RequestContext);
}
bool isAjaxRequest = filterContext.RequestContext.HttpContext.Request.IsAjaxRequest();
Func<string, JsonResult> setResult = delegate(string msg)
{
DataResultBoolean response = new DataResultBoolean()
{
IsValid = false,
Message = msg,
MessageType = DataResultMessageType.Error,
Data = false
};
JsonResult result = new JsonResult();
result.Data = response;
return result;
};
if (!this.CheckSessionExpired(filterContext.HttpContext))
{
if (isAjaxRequest)
{
filterContext.Result = setResult($customNamespace$.Resources.General.GeneralTexts.SessionExpired);
}
else
{
filterContext.Result = new RedirectResult(ErrorUrlHelper.SessionExpired(urlHelper));
}
}
// break execution in case a result has been already set
if (filterContext.Result != null)
return;
if (!this.CheckIsAutohrized(filterContext.HttpContext))
{
if (isAjaxRequest)
{
filterContext.Result = setResult($customNamespace$.Resources.General.GeneralTexts.PermissionDenied);
}
else
{
filterContext.Result = new RedirectResult(ErrorUrlHelper.UnAuthorized(urlHelper));
}
}
}
开发者ID:jordivila,项目名称:Net_MVC_NLayer_Generator,代码行数:56,代码来源:AuthorizeAttibuteExtended.cs
示例14: ActionLinkImage
public static MvcHtmlString ActionLinkImage(this HtmlHelper htmlHelper, string imageLocation, string altTag, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection);
var link = new TagBuilder("a");
link.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routeValues));
link.MergeAttribute("target", (string)htmlAttributes["target"]); htmlAttributes.Remove("target");
link.InnerHtml = htmlHelper.Image(imageLocation, altTag, htmlAttributes).ToString();
return MvcHtmlString.Create(link.ToString(TagRenderMode.Normal));
}
开发者ID:wduffy,项目名称:Toltech.Mvc,代码行数:11,代码来源:ActionLinkImage.cs
示例15: BuildPreviousLink
private static string BuildPreviousLink(UrlHelper urlHelper, QueryOptions queryOptions, string actionName)
{
return string.Format(
"<a href=\"{0}\"><span aria-hidden=\"true\">←</span> Previous</a>",
urlHelper.Action(actionName, new
{
SortOrder = queryOptions.SortOrder,
SortField = queryOptions.SortField,
CurrentPage = queryOptions.CurrentPage - 1,
PageSize = queryOptions.PageSize
}));
}
开发者ID:nikkiLuan,项目名称:Knockout-MVC,代码行数:12,代码来源:HtmlHelperExtensions.cs
示例16: UrlHelper_ButtonLink_Should_JavaScript_Escape_URLs
public void UrlHelper_ButtonLink_Should_JavaScript_Escape_URLs()
{
var controllerContext = new ControllerContext();
var engineContext = new StubEngineContext { CurrentControllerContext = controllerContext, UrlInfo = new UrlInfo("", "home", "index", "", "") };
var helper = new UrlHelper(engineContext);
helper.UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), null);
helper.UrlBuilder.UseExtensions = false;
controllerContext.Helpers.Add(helper);
Assert.AreEqual("<button type=\"button\" onclick=\"javascript:window.location.href = '/MyController/MyAction?ProductName=Jack\\'s+Mine'\">MyButton</button>", helper.ButtonLink("MyButton", DictHelper.CreateN("controller", "MyController").N("action", "MyAction").N("queryString", "ProductName=Jack's Mine")));
}
开发者ID:candland,项目名称:Castle.MonoRail,代码行数:12,代码来源:MR-ISSUE-535.cs
示例17: BuildKnockoutSortableLink
public static MvcHtmlString BuildKnockoutSortableLink(this HtmlHelper htmlHelper,
string fieldName, string actionName, string sortField)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
return new MvcHtmlString(string.Format(
"<a href=\"{0}\" data-bind=\"click: pagingService.sortEntitiesBy\"" +
" data-sort-field=\"{1}\">{2} " +
"<span data-bind=\"css: pagingService.buildSortIcon('{1}')\"></span></a>",
urlHelper.Action(actionName),
sortField,
fieldName));
}
开发者ID:chimpinano,项目名称:knockoutjs-examples,代码行数:13,代码来源:HtmlHelperExtensions.cs
示例18: JsHttpHandler
static JsHttpHandler( )
{
operations = new Dictionary<string, OperationDelegate>
{
{ "Route", (name, context)=>{
var Url = new UrlHelper(context);
return Url.RouteUrl(name, new { locale = System.Threading.Thread.CurrentThread.CurrentCulture.Name });
}},
{ "Resx", (name, context)=>{
return LocalizationResx.ResourceManager.GetString(name, LocalizationResx.Culture);
}}
};
}
开发者ID:NonameProject,项目名称:Noname,代码行数:13,代码来源:JsHttpHandler.cs
示例19: Image
public static MvcHtmlString Image(this HtmlHelper htmlHelper, string imageLocation, string altTag, IDictionary<string, object> htmlAttributes)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection);
if (string.IsNullOrEmpty(imageLocation))
throw new ArgumentException("Value cannot be null or empty.", "imageLocation");
var image = new TagBuilder("img");
image.MergeAttributes<string, object>(htmlAttributes);
image.MergeAttribute("src", urlHelper.Content(imageLocation));
image.MergeAttribute("alt", htmlHelper.Encode(altTag));
return MvcHtmlString.Create(image.ToString(TagRenderMode.SelfClosing));
}
开发者ID:wduffy,项目名称:Toltech.Mvc,代码行数:14,代码来源:Image.cs
示例20: Tab
/// <summary>
/// Creates the appropriate li and anchor tags for use inside of the skeleton tabs.
/// </summary>
/// <param name="this">Instance of HtmlHelper being extended.</param>
/// <param name="tabText">The text displayed on the tab.</param>
/// <param name="activeControllerName">Name of the active controller. This is used to determine which anchor tag in
/// the tabs gets the 'active' css class.</param>
/// <returns></returns>
public static MvcHtmlString Tab(this HtmlHelper @this, string tabText, string activeControllerName)
{
var text = String.IsNullOrEmpty(tabText) ? "My Tasks" : tabText;
var controllerName = String.IsNullOrEmpty(activeControllerName) ? "Tasks" : activeControllerName;
var url = new UrlHelper(@this.ViewContext.RequestContext);
var link = new Element("a").AddAttribute("href", url.Action("Index", controllerName)).Update(tabText);
var currentController = @this.ViewContext.RequestContext.RouteData.Values["controller"].ToString();
if (controllerName.Equals(currentController, StringComparison.OrdinalIgnoreCase))
link.CssClasses.Add("active");
return MvcHtmlString.Create(new Element("li", link));
}
开发者ID:chrcar01,项目名称:SimpleTasks,代码行数:22,代码来源:HtmlHelperExtensions.cs
注:本文中的UrlHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论