Tag-helper trong Asp.net Core là gì?

{{FormatNumbertoThousand(model.total_like)}} lượt thích
3.187 lượt xem

Nó là một tính năng được cung cấp bởi Razor view-engine cho phép chúng ta viết mã server-side để tạo và hiển thị các phần tử HTML trong view (Razor). Tag-helper là các lớp C# thường được dùng để tạo view bằng cách thêm các phần tử HTML. Chức năng của tag-helper rất giống với HTML-helper của Asp.net MVC.

//HTML Helper
@Html.TextBoxFor(model => model.FirstName, 
new { @class = "form-control", placeholder = "Enter Your First Name" }) 

//content with tag helper
<input asp-for="FirstName" placeholder="Enter Your First Name" 
class="form-control" /> 

//Equivalent HTML
<input placeholder="Enter Your First Name" class="form-control" 
id="FirstName" name="FirstName" value="" type="text"> 
{{login.error}}