Saturday 23 November 2013

ActionLink in HTML Helper Class in MVC

ActionLink in HTML Helper Class in MVC

ActionLink is used to generate hyperlink in MVC using HTML Helper Class.

For Example:-

@Html.ActionLink("Login","Welcome")

In this example Login is the Text which shows on link and Welcome is the view on which it will redirected when we click on this actionlink.

Actionlink method also allows us to bind any data on this link. 
We can access this data on redirected page.

@Html.ActionLink("Login", "Welcome", new { UserId = "isha123" })

In this example I bound data using name UserId. I can access this id on Welcome view as a parameter.

public ActionResult Welcome(string UserId)
        {
            Response.Write("Hello " + UserId);

            return View();
        }

In this way we can bind data on this actionlink which we can access on the redirected page.


3 comments: