asp.net core ViewComponent中直接返回HTML的方法!!! how to return html code direct from a viewcomponent with out a view.cshtml

 利用组件不借助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>")); } } }

 

 

posted @ 2020-12-04 17:49  IDOER  阅读(449)  评论(0编辑  收藏  举报