Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. What is the advantage of using Tag Helpers in ASP.Net MVC 5

What is the advantage of using Tag Helpers in ASP.Net MVC 5

Scheduled Pinned Locked Moved ASP.NET
asp-netcsharphtmldotnetcom
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tridip Bhattacharjee
    wrote on last edited by
    #1

    apologized that i am not very good in asp.net mvc that i would like to confess. i just come across a good write up for asp.net 5 new feature from this url http://stephenwalther.com/archive/2015/02/24/top-10-changes-in-asp-net-5-and-mvc-6 from there i heard about a term called Tag Helpers in ASP.Net MVC 5 and i saw there people say before developer create form this below way

    @model MyProject.Models.Product

    @using (Html.BeginForm())
    {

        @Html.LabelFor(m => p.Name, "Name:")
        @Html.TextBoxFor(m => p.Name)
    
    
    <input type="submit" value="Create" />
    

    }

    and now people can code the same with tag helper the below way

    @model MyProject.Models.Product
    @addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"

    <form asp-controller="Products" asp-action="Create" method="post">

        <label asp-for="Name">Name:</label>
        <input asp-for="Name" />
    
    
    <input type="submit" value="Save" />
    

    </form>

    they use some few new syntax called asp-controller,asp-for etc but what it will do.....how and why people would be benefited by using this new syntax asp-controller,asp-for etc. so please some one help me to understand this new tag helper concept and how it will make a developer life easier. thanks

    tbhattacharjee

    A 2 Replies Last reply
    0
    • T Tridip Bhattacharjee

      apologized that i am not very good in asp.net mvc that i would like to confess. i just come across a good write up for asp.net 5 new feature from this url http://stephenwalther.com/archive/2015/02/24/top-10-changes-in-asp-net-5-and-mvc-6 from there i heard about a term called Tag Helpers in ASP.Net MVC 5 and i saw there people say before developer create form this below way

      @model MyProject.Models.Product

      @using (Html.BeginForm())
      {

          @Html.LabelFor(m => p.Name, "Name:")
          @Html.TextBoxFor(m => p.Name)
      
      
      <input type="submit" value="Create" />
      

      }

      and now people can code the same with tag helper the below way

      @model MyProject.Models.Product
      @addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"

      <form asp-controller="Products" asp-action="Create" method="post">

          <label asp-for="Name">Name:</label>
          <input asp-for="Name" />
      
      
      <input type="submit" value="Save" />
      

      </form>

      they use some few new syntax called asp-controller,asp-for etc but what it will do.....how and why people would be benefited by using this new syntax asp-controller,asp-for etc. so please some one help me to understand this new tag helper concept and how it will make a developer life easier. thanks

      tbhattacharjee

      A Offline
      A Offline
      Anurag Gandhi
      wrote on last edited by
      #2

      Hi, This is an attempt to make you feel that you are not doing mixed coding (Client side and server side). Also, it may reduce the context switching (IMHO). Moreover, tag based syntax is good for simplicity. Just think if you have to add 10 attributes in your html helper. Your code becomes un-readable. With tag helper, your server side and client side tags and attributes will go hand in hand with much improved readability.

      Life is a computer program and everyone is the programmer of his own life.

      T 1 Reply Last reply
      0
      • A Anurag Gandhi

        Hi, This is an attempt to make you feel that you are not doing mixed coding (Client side and server side). Also, it may reduce the context switching (IMHO). Moreover, tag based syntax is good for simplicity. Just think if you have to add 10 attributes in your html helper. Your code becomes un-readable. With tag helper, your server side and client side tags and attributes will go hand in hand with much improved readability.

        Life is a computer program and everyone is the programmer of his own life.

        T Offline
        T Offline
        Tridip Bhattacharjee
        wrote on last edited by
        #3

        thanks for your reply. can you please discuss the advantage with sample code whatever you said in your answer. if u plzz explain with small small sample code then i may understand. thanks

        tbhattacharjee

        A J 2 Replies Last reply
        0
        • T Tridip Bhattacharjee

          thanks for your reply. can you please discuss the advantage with sample code whatever you said in your answer. if u plzz explain with small small sample code then i may understand. thanks

          tbhattacharjee

          A Offline
          A Offline
          Anurag Gandhi
          wrote on last edited by
          #4

          I would recommend you to visit http://asp.net/mvc and other websites which talk about it. You will get many examples there. Please don't hesitate to ask if you have specific pin-point question. TagHelpers[^]

          Life is a computer program and everyone is the programmer of his own life.

          1 Reply Last reply
          0
          • T Tridip Bhattacharjee

            thanks for your reply. can you please discuss the advantage with sample code whatever you said in your answer. if u plzz explain with small small sample code then i may understand. thanks

            tbhattacharjee

            J Offline
            J Offline
            Joshua Omundson
            wrote on last edited by
            #5

            Your sample code has a perfect example. So as it is now you have a form like so

            @model MyProject.Models.Product

            @using (Html.BeginForm())
            {

                @Html.LabelFor(m => p.Name, "Name:")
                @Html.TextBoxFor(m => p.Name)
            
            
            <input type="submit" value="Create" />
            

            }

            Just by looking at this code I don't really know where the form is going to be posted to. Also your standard HTML controls are created using specific C# HTML Helpers, which can make the html a little confusing for some. Now taking a look at the code that uses Tag Helpers, the HTML is much more readable.

            @model MyProject.Models.Product
            @addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"

            <form asp-controller="Products" asp-action="Create" method="post">

                <label asp-for="Name">Name:</label>
                <input asp-for="Name" />
            
            
            
            <input type="submit" value="Save" />
            

            </form>

            I know exactly where this form is going to post back to. And I also know where my HTML elements are and where my C# code is. For me, it makes the view a whole lot easier to read and understand.

            1 Reply Last reply
            0
            • T Tridip Bhattacharjee

              apologized that i am not very good in asp.net mvc that i would like to confess. i just come across a good write up for asp.net 5 new feature from this url http://stephenwalther.com/archive/2015/02/24/top-10-changes-in-asp-net-5-and-mvc-6 from there i heard about a term called Tag Helpers in ASP.Net MVC 5 and i saw there people say before developer create form this below way

              @model MyProject.Models.Product

              @using (Html.BeginForm())
              {

                  @Html.LabelFor(m => p.Name, "Name:")
                  @Html.TextBoxFor(m => p.Name)
              
              
              <input type="submit" value="Create" />
              

              }

              and now people can code the same with tag helper the below way

              @model MyProject.Models.Product
              @addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"

              <form asp-controller="Products" asp-action="Create" method="post">

                  <label asp-for="Name">Name:</label>
                  <input asp-for="Name" />
              
              
              <input type="submit" value="Save" />
              

              </form>

              they use some few new syntax called asp-controller,asp-for etc but what it will do.....how and why people would be benefited by using this new syntax asp-controller,asp-for etc. so please some one help me to understand this new tag helper concept and how it will make a developer life easier. thanks

              tbhattacharjee

              A Offline
              A Offline
              Anurag Gandhi
              wrote on last edited by
              #6

              Apart from already explained answer, on a side note just want to clarify that it is for Asp.Net MVC 6. Not MVC 5. I know the version number of Asp.Net, C#, MVC and Visual Studio often confuse people. :) Next Release versions: Asp.Net: 5 Asp.Net MVC: 6 C#: 6 Visual Studio: 2015

              Life is a computer program and everyone is the programmer of his own life.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups