标记帮助程序与HTML帮助程序“使用IHtmlHelper.Partial可能会导致应用程序死锁". [英] Tag Helper vs HTML Helper "Use of IHtmlHelper.Partial may result in application deadlocks"

查看:220
本文介绍了标记帮助程序与HTML帮助程序“使用IHtmlHelper.Partial可能会导致应用程序死锁".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用部分视图的ASP.NET Core MVC项目.当我编译它时,会收到以下警告:

I have an ASP.NET Core MVC project that uses partial views. When I compile it I receive the following warning:

使用IHtmlHelper.Partial可能会导致应用程序死锁. 考虑使用Tag Helper或IHtmlHelper.PartialAsync.

Use of IHtmlHelper.Partial may result in application deadlocks. Consider using Tag Helper or IHtmlHelper.PartialAsync.

标记助手和HTML助手之间的区别是什么,这会导致应用程序死锁?

What is the difference between what the Tag Helper does and what the HTML Helper does, that would cause an application deadlock?

通过阅读此处的文档,我的理解是,Tag Helper方法旨在使标记更易于阅读并允许Intellisense支持.换句话说,我认为这两种方法只是同一件事的语法不同,但显然这里还有其他事情.

From reading documentation here, my understanding was that the Tag Helper approach aims to make the markup easier to read and allows Intellisense support. In other words I thought the two approaches were just different syntax for the same thing, but clearly something else is going on here.

是否应该始终使用Tag Helper而不是HTML Helper?

Should one always use a Tag Helper instead of a HTML Helper?

推荐答案

标记助手是ASP.NET Core的新增功能,除了您提到的优点外,还值得一提:它们是由Razor在服务器上处理的(更强大) ,可靠和可维护),您可以非常简单地创建自己的自定义TagHelpers(实现ITagHelper接口或从TagHelper类继承,并通过定义其实现来覆盖Process方法).

Tag Helpers are new to ASP.NET Core and besides the advantages you have mentioned, it is worth mentioning: they are processed by Razor on the server (more robust, reliable and maintainable) and you can create your own custom TagHelpers very simply (implement the ITagHelper interface or inherit from the TagHelper class and override the Process method by defining its implementation).

这篇关于标记帮助程序与HTML帮助程序“使用IHtmlHelper.Partial可能会导致应用程序死锁".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆