2017-06-13 66 views
0

ASP.NET Core中,我需要從名稱空間Microsoft.AspNetCore.Mvc.Razor.HelperResult中獲取內容值,並將該值賦給變量,但是它將該名稱空間分配給該變量。如何從名稱空間獲取內容「Microsoft.AspNetCore.Mvc.Razor.HelperResult」

當我使用名稱空間System.Web.WebPages.HelperResult並將該內容分配給變量時,它在MVC中正常工作。 (內容是一些html元素)。

請檢查圖片找到問題。

我的代碼:

Variable with namespace name as value

+0

如何關係到'git','github'和'gitlab'標記你的問題? – Ignas

回答

0

.NET CoreHelperResult回報IHtmlContent代替IHtmlString

對於IHtmlContent它可能是方便的使用像一個擴展提到here

public static IHtmlContent GetList(this IHtmlHelper helper) 
{ 
    var listHtml = new HtmlContentBuilder(); 
    listHtml.AppendHtml("<ol><li>"); 
    listHtml.AppendHtml(helper.ActionLink("foo", "bar", "example")); 
    listHtml.AppendHtml("</li></ol>"); 
    return listHtml; 
} 
相關問題