利用组件不借助view.cshtml的方法直接返回的方法
how to return html code direct from a viewcomponent with out a view.cshtml
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ViewComponents; namespace MySite.ViewComponents { [ViewComponent(Name = "TestViewComponent")] public class TestViewComponent : ViewComponent { public TestViewComponent() { } public IViewComponentResult Invoke() { return new HtmlContentViewComponentResult(new HtmlString("hello - <b>我是个王八蛋</b>")); } } }