问题描述
使用MVC 6.0 beta1时,我可以在MVC源代码中看到一个实用程序 DefaultTemplatesUtilities.cs 发送至GetHtmlHelper.但是,此HtmlHelper仅返回在CreateViewEngine()方法中设置的格式化输出.
When using the MVC 6.0 beta1, I can see in the MVC source that there is a utility DefaultTemplatesUtilities.cs to GetHtmlHelper. But this HtmlHelper only returns formatted output that is setup in CreateViewEngine() method.
如何创建viewEngine
以便呈现普通的html.
How can I create a viewEngine
so that the normal html is rendered.
我需要通过代码获取HtmlHelper
并使用它生成一些html.即htmlHelper.EditorFor(model=>model.Property)
I need to get HtmlHelper
through code and use it to generate some html. i.e. htmlHelper.EditorFor(model=>model.Property)
推荐答案
您可以使用依赖注入到控制器构造函数来获取HtmlHelper.
You can get HtmlHelper using Dependency Injection to your controller constructor.
检查我的答案以获取更多详细代码.
Check my Answer for more detailed code.
这篇关于如何在MVC 6中获取HtmlHelper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!