ASP.NET 5 MVC6 RC1 には、従来の「画面の左側」のメイン メニューを表すように設計された ViewComponent があります。
各メニュー項目リンクを表す最初の TagHelper を作成しています。
ハイパーリンクを作成しようとしている部分で立ち往生しています。
解決方法~/dashboard/summary?
このページのメニューを表示すると、リンクが のように表示され/dashboard/~/dashboard/summary
ます。
@Url.Content("...")
@Url.Content("...")
ie が表示され、剃刀として処理されません。タグ ヘルパーは pure を出力します。
最終的には .net コアの展開可能なソリューションを目指しているので、理想的には、ソリューションが .NET コアと互換性があることを望みます。
下記参照:
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>
}
}
ありがとう!ダン。