Skip to main content

Posts

Showing posts with the label Tag Helpers

All about Tag Helpers in ASP.NET Core 2.0

This time rather than jumping directly into the topic, let's have a look at the Login form code which you must have definitely seen while working on MVC application. What do you think about the above code snippet? Indeed, it works alright, but there are few problems with this. But the major problem is its a bit messy and difficult to read due to excessive use of @. So, now we have understood the problem, what is the solution? Here comes the Tag Helpers for our rescue. Let's quickly have a look at the code generated by the ASP.NET Core framework for the same functionality: The above code looks much cleaner. Isn’t it? If it looks interesting to you, we should learn more about it. What are Tag Helpers Tag Helpers are classes written in C# but are attached to HTML elements in order to run server-side code from Razor view. In other words, view created in HTML has its presentation logic defined in C#, which is ultimately executed on the w

Tag Helpers in ASP.NET Core 1.0

Exclusive Amazon Deals This article is for those who would like to use Tag Helpers over old Razor/HTML helpers. Tag Helpers, another new feature of ASP.NET Core. Let’s quickly have a look at it. What are Tag Helpers? As per ASP.NET documentation:                     " Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files ". Tag Helpers are somewhat similar to HTML Helpers/Razor Helpers introduced in previous version of ASP.NET MVC but those helpers were not that easy to understand for web designers because of inline C# method calls. As web designers are more inclined towards HTML, a simpler and comfortable approach was required. Fortunately, ASP.NET Core 1.0 provided that. Now one need not to use HTML Helpers to build cshtml forms. Means when you had to write this: Now you can write this: As you can see a bove format is very easy to understand as it is purely a HTML syntax. How Tag Helpers wor