在 ASP.NET 5 MVC6 RC1 - 我有一个 ViewComponent 旨在代表我传统的“屏幕左侧”主菜单。
我正在编写我的第一个 TagHelper 来表示每个菜单项链接。
我被困在我试图创建超链接的部分。
我该如何解决~/dashboard/summary?
如果我在此页面上显示菜单,则链接显示为/dashboard/~/dashboard/summary
。
@Url.Content("...")
显示@Url.Content("...")
ie 未作为剃刀处理。标签助手输出纯。
理想情况下,我希望该解决方案与 .NET Core 兼容,因为我最终的目标是实现 .NET Core 可部署解决方案。
见下文:
namespace Website
{
/// <summary>
/// <MainMenuLink area="" controller="" action=""></MainMenuLink>
///
/// to render
///
/// <a href="~/account/manage/ChangePassword" class="list-group-item @GetClassName("manage", "changepassword")">
/// <p class="list-group-item-text"><i class="fa fa-terminal"></i> Change my password</p>
/// </a>
///
///
/// </summary>
[HtmlTargetElement(Attributes = "area, controller, action")]
public class MainMenuLinkTagHelper : TagHelper
{
[HtmlAttributeName("area")]
public string Area { get; set; }
[HtmlAttributeName("controller")]
public string Controller { get; set; }
[HtmlAttributeName("action")]
public string Action { get; set; }
public UrlHelper urlHelper { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "a"; // Works
// Stuck here - I want ~/ to resolve to the base root.
// At the moment the address is here is localhost:XXXXX/dashboard/~/dashboard/summary
// Would prefer to use a method which can be used with .net core and not System.Web
output.Attributes.Add("href", "~/dashboard/summary");
output.Content.SetHtmlContent("Click me");
}
/// <summary>
}
}
谢谢!担。