mvc 5 vs mvc 6

MVC 6 tag helpers vNext intelligence

An Introduction to Tag Helpers

Tag Helpers is the biggest feature of MVC 6 that help us to creating and rendering HTML elements in Razor views.

From ASP.NET documentation,

"Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files."

Example for Using Tag Helpers,

Before using Tag Helpers in MVC razor view,

@model MVC6Protal.Models.User

@using (Html.BeginForm())
{
    <div>
        @Html.LabelFor(m => m.Name, "User Name ")
        @Html.TextBoxFor(m => m.Name)
    </div>
    <div>
        @Html.LabelFor(m => m.Email, "User Email ")
        @Html.TextBoxFor(m => m.Email)
    </div>
    <input type="submit" value="Create" />
}

After using Tag Helpers in MVC razor view,

    @model MVC6Protal.Models.User
    @addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"
<form asp-controller="Users" asp-action="Create" method="post">
    <div>
        <label asp-for="Name">User Name </label>
        <input asp-for="Name" />
    </div>
    <div>
        <label asp-for="Email">User Email </label>
        <input asp-for="Email" />
    </div>
    <input type="submit" value="Save" />
</form>


For more detail go to


ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.