Sunday, March 15, 2015

Using Html.ActionLink to call action on different controller

http://stackoverflow.com/questions/776781/using-html-actionlink-to-call-action-on-different-controller

<%= Html.ActionLink("Details", "Details", "Product", new { id=item.ID }, null) %>
It fires HtmlHelper.ActionLink(string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
http://stackoverflow.com/questions/2036305/how-to-specify-an-area-name-in-an-action-link


Html.ActionLink("Link Text", "ActionName", "ControllerName", new { Area = "AreaName" }, new{})

Html.ActionLink("home", "Index", new { area = "", controller = "Home" })
Html.ActionLink("Home", "Index", "Home", new { Area = "root" }, new{})


@if (Request.IsAuthenticated)
{
    <text>
    Hello, @Html.ActionLink(User.Identity.Name, "Manage", "Account", new { area = "" }, htmlAttributes: new { @class = "username", title = "Manage" })!
    @using (Html.BeginForm("LogOff", "Account", new { area = "" }, FormMethod.Post, new { id = "logoutForm" }))
 {
        @Html.AntiForgeryToken()
        <a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>
 }
    </text>
}
else
{
    <ul>
        <li>@Html.ActionLink("Register", "Register", "Account", new { area = "" }, htmlAttributes: new { id = "registerLink" })</li>
        <li>@Html.ActionLink("Log in", "Login", "Account", new { area = "" }, htmlAttributes: new { id = "loginLink" })</li>
    </ul>
}

No comments:

Post a Comment