Follow us

Header Ads

TagHelpers_Learn in Asp.Net Core

TagHelpers_Learn in Asp.Net Core

Controllers[Folder]

HomeController.cs

using Microsoft.AspNetCore.Mvc;

namespace TagHelpers_Learn.Controllers
{
    public class HomeController : Controller
    {
        // It is necessary for adding on url in startup.cs file
        [Route("")]
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult About()
        {
            return View();
        }
        public int Details(int id)
        {
            return id;
        }
    }
}

Views[Folder]

Home


@{
    ViewData["Title"] = "Index";
}

<h1>Index</h1>
<!--Benifits of using TagHelpers-->
<a href="Home/About">About Page 1</a>
<br />
<a asp-controller="Home" asp-action="About">About page 4</a>


<!--It is Normal Html Tag-->
<a href="Home/About">About Page 1</a>
<!--About is action method name and Home is controller name-->
@Html.ActionLink("About Page2","About","Home")
<br />
<a href="@Url.Action("About","Home")">About Page 3</a>
<br />
<!--It is original example of tag helpers-->
<a asp-controller="Home" asp-action="About">About Page 4</a>
<br />
<br />
<!--It is Normal Html Tag-->
<a href="Home/Details/1">Detils Page 1</a>
<!--About is action method name and Home is controller name-->
@Html.ActionLink("Details Page2","Details","Home",new {id=1})
<br />
<a href="@Url.Action("Details","Home",new {id=1})">Details Page 3</a>
<br />
<!--It is original example of tag helpers-->
<a asp-controller="Home" asp-action="Details" asp-route-id="1">Details Page 4</a>


Post a Comment

0 Comments