In this blog we will discuss about
the @HTMLHelper class and how to create the HTML Anchor by using @Html.ActionLink.
@HTMLHelper Class:
@Html is used in
ASP.NET MVC to render HTML elements like TextBox, Button etc. and it binds the
model object to HTML control and display the object’s value and while posting
the page, it binds the control value to model object.
@Html.ActionLink Method:
HTMLHelper object has ActionLink method to
render the anchor HTML element with specified link text and action name with
controller.
Here is examples of Action methods:
·
@Html.ActionLink("Home", "Home", "Person")
Generates <a
href="/Person/Home" >Home</a>
·
IF
you are not passing controller, by default it will take current page controller
name.
@Html.ActionLink("Home", "Home")
·
Action
and Controller with parameter are given:
@Html.ActionLink("Home", "Home", "Person", new {
PersonID = Model.ID}, null )
Generates <a
href="../Person/Home?PersonID=1212" >Home</a>
·
Anchor
with html ID
@Html.ActionLink("Home", "Home", "Person", new {
PersonID = Model.ID}, new { id = "HomeLinkID"} )
Generates <a
href="../Person/Home?PersonID=1212" id="HomeLinkID"
>Home</a>
Thanks for visiting!!
No comments:
Post a Comment