Tag Helpers是一个非常好用的工具
官方链接:Tag Helpers in ASP.NET Core | Microsoft Docs
What are Tag Helpers?
Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files. For example, the built-in ImageTagHelper can append a version number to the image name. Whenever the image changes, the server generates a new unique version for the image, so clients are guaranteed to get the current image (instead of a stale cached image). There are many built-in Tag Helpers for common tasks - such as creating forms, links, loading assets and more - and even more available in public GitHub repositories and as NuGet packages. Tag Helpers are authored in C#, and they target HTML elements based on element name, attribute name, or parent tag. For example, the built-in LabelTagHelper can target the HTML
Tag Helpers常用在用在表单(Forms)中,使用示例如下:
Member.cs:
public class Member
{
public int PersonId {
get; set; }
public string Name {
get; set; }
[EmailAddress]
public string Email {
get; set; }
[DataType(DataType.Password)]
public string Password {
get; set; }
[DataType(DataType.PhoneNumber)]
public string Telephone {
get; set<

本文介绍了ASP.NET Core中的Tag Helpers,这是一种让服务器端代码参与Razor文件中HTML元素创建和渲染的技术。Tag Helpers如ImageTagHelper可以为图片添加版本号,确保客户端总是获取最新图片。它们针对HTML元素名、属性名或父标签进行操作,简化了HTML和C#在Razor视图间的切换。文中还展示了Tag Helpers在表单验证中的应用。
最低0.47元/天 解锁文章
893

被折叠的 条评论
为什么被折叠?



